From 9b8646cba91e9815325a16df6e9bc03447345225 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 14 Oct 2012 16:35:56 +0200 Subject: initial import of eenvaders code base --- .gitignore | 68 +++++++++++ AUTHORS | 1 + COPYING | 1 + ChangeLog | 1 + Makefile.am | 6 + NEWS | 1 + README | 5 + autogen.sh | 17 +++ configure.ac | 55 +++++++++ data/Makefile.am | 18 +++ data/elife.edc | 48 ++++++++ m4/efl_binary.m4 | 71 +++++++++++ src/Makefile.am | 29 +++++ src/elife.c | 106 ++++++++++++++++ src/elife_edje_external.c | 192 +++++++++++++++++++++++++++++ src/elife_evas_smart.c | 304 ++++++++++++++++++++++++++++++++++++++++++++++ src/elife_evas_smart.h | 8 ++ 17 files changed, 931 insertions(+) create mode 100644 .gitignore create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 ChangeLog create mode 100644 Makefile.am create mode 100644 NEWS create mode 100644 README create mode 100755 autogen.sh create mode 100644 configure.ac create mode 100644 data/Makefile.am create mode 100644 data/elife.edc create mode 100644 m4/efl_binary.m4 create mode 100644 src/Makefile.am create mode 100644 src/elife.c create mode 100644 src/elife_edje_external.c create mode 100644 src/elife_evas_smart.c create mode 100644 src/elife_evas_smart.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a8e7ece --- /dev/null +++ b/.gitignore @@ -0,0 +1,68 @@ +/INSTALL +/Makefile +/Makefile.in +/aclocal.m4 +/autom4te.cache/ +/config.guess +/config.h +/config.h.in +/config.log +/config.status +/config.sub +/configure +/depcomp +/install-sh +/libtool +/ltmain.sh +/m4/libtool.m4 +/m4/ltoptions.m4 +/m4/ltsugar.m4 +/m4/ltversion.m4 +/m4/lt~obsolete.m4 +/missing +/src/.deps/ +/src/.libs/ +/src/Makefile +/src/Makefile.in +/src/elife +/src/*.lo +/src/*.o +/src/module.la +/stamp-h1 +/compile +/data/Makefile +/data/Makefile.in +/data/elife.edj +/intl +/ABOUT-NLS +/config.rpath +/m4/codeset.m4 +/m4/gettext.m4 +/m4/glibc2.m4 +/m4/glibc21.m4 +/m4/iconv.m4 +/m4/intdiv0.m4 +/m4/intl.m4 +/m4/intldir.m4 +/m4/intlmacosx.m4 +/m4/intmax.m4 +/m4/inttypes-pri.m4 +/m4/inttypes_h.m4 +/m4/lcmessage.m4 +/m4/lib-ld.m4 +/m4/lib-link.m4 +/m4/lib-prefix.m4 +/m4/lock.m4 +/m4/longlong.m4 +/m4/nls.m4 +/m4/po.m4 +/m4/printf-posix.m4 +/m4/progtest.m4 +/m4/size_max.m4 +/m4/stdint_h.m4 +/m4/uintmax_t.m4 +/m4/visibility.m4 +/m4/wchar_t.m4 +/m4/wint_t.m4 +/m4/xsize.m4 +/po/ diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..4e42cdc --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Laurent Ghigonis diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/COPYING @@ -0,0 +1 @@ + diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ChangeLog @@ -0,0 +1 @@ + diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..215bf9f --- /dev/null +++ b/Makefile.am @@ -0,0 +1,6 @@ +AUTOMAKE_OPTIONS = 1.4 foreign +MAINTAINERCLEANFILES = Makefile.in + +SUBDIRS = src data + +ACLOCAL_AMFLAGS = -I m4 diff --git a/NEWS b/NEWS new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/NEWS @@ -0,0 +1 @@ + diff --git a/README b/README new file mode 100644 index 0000000..8847b7e --- /dev/null +++ b/README @@ -0,0 +1,5 @@ +elife - Game of life / Living graphic +2012 Laurent Ghigonis + +Packaging and general structure from EEnvader.fractal by Boris Faure + diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000..ae01364 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,17 @@ +#!/bin/sh + +rm -rf autom4te.cache +rm -f aclocal.m4 ltmain.sh + +touch README + +echo "Running autopoint..." ; autopoint -f || : +echo "Running aclocal..." ; aclocal -I m4 $ACLOCAL_FLAGS || exit 1 +echo "Running autoheader..." ; autoheader || exit 1 +echo "Running autoconf..." ; autoconf || exit 1 +echo "Running libtoolize..." ; (libtoolize --copy --automake || glibtoolize --automake) || exit 1 +echo "Running automake..." ; automake --add-missing --copy --gnu || exit 1 + +if [ -z "$NOCONFIGURE" ]; then + ./configure "$@" +fi diff --git a/configure.ac b/configure.ac new file mode 100644 index 0000000..7c19b4b --- /dev/null +++ b/configure.ac @@ -0,0 +1,55 @@ +dnl Process this file with autoconf to produce a configure script. + +# get rid of that stupid cache mechanism +rm -f config.cache + +AC_INIT(elife, 0.1, laurent@p1sec.com) +AC_PREREQ(2.52) +AC_CONFIG_SRCDIR(configure.ac) +AC_CANONICAL_BUILD +AC_CANONICAL_HOST +AC_ISC_POSIX + +AM_INIT_AUTOMAKE(1.6) +AM_CONFIG_HEADER(config.h) +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) + +AC_PROG_CC_C99 +AC_HEADER_STDC +AC_C_CONST +AM_PROG_CC_C_O + +define([AC_LIBTOOL_LANG_CXX_CONFIG], [:])dnl +define([AC_LIBTOOL_LANG_F77_CONFIG], [:])dnl +AC_PROG_LIBTOOL + +m4_ifdef([AM_GNU_GETTEXT_VERSION], [ +AM_GNU_GETTEXT_VERSION([0.17]) +]) + +PKG_PROG_PKG_CONFIG +PKG_CHECK_MODULES([ELIFE], [edje ecore-evas ecore evas eina]) +datadir_edj=$($PKG_CONFIG --variable=prefix enlightenment)/share/enlightenment/data/backgrounds + +EFL_WITH_BIN([edje], [edje-cc], [edje_cc]) +vmaj=$($PKG_CONFIG --variable=vmaj edje) +MODULE_ARCH="$host_os-$host_cpu-$vmaj.0.0" +AC_SUBST(MODULE_ARCH) +AC_DEFINE_UNQUOTED(MODULE_ARCH, "$MODULE_ARCH", "Module architecture") + +datadir=$(pkg-config --variable=modules edje)/${PACKAGE} +AC_ARG_ENABLE(homedir-install, + AS_HELP_STRING([--enable-homedir-install], [Install module in homedir]), + [ + datadir="${HOME}/.edje/modules/${PACKAGE}"; + datadir_edj="${HOME}/.e/e/backgrounds" + ] +) +AC_SUBST(datadir_edj) + +AC_OUTPUT([ +Makefile +data/Makefile +src/Makefile +], [ +]) diff --git a/data/Makefile.am b/data/Makefile.am new file mode 100644 index 0000000..8664660 --- /dev/null +++ b/data/Makefile.am @@ -0,0 +1,18 @@ +AUTOMAKE_OPTIONS = 1.4 foreign +MAINTAINERCLEANFILES = Makefile.in + +EDJE_FLAGS = -v + +filesdir = @datadir_edj@ +files_DATA = elife.edj + +EXTRA_DIST = elife.edc + +elife.edj: elife.edc + $(edje_cc) $(EDJE_FLAGS) $< $@ + +clean-local: + rm -rf elife.edj *~ + +uninstall: + rm -rf $(DESTDIR)@datadir_edj@/elife.edj diff --git a/data/elife.edc b/data/elife.edc new file mode 100644 index 0000000..be56255 --- /dev/null +++ b/data/elife.edc @@ -0,0 +1,48 @@ +externals { + external: "elife"; +} + +collections { + group { + name: "e/desktop/background"; + + script { + public clock_cb(unused) { + emit("elife:refresh", "☃"); + timer(30, "clock_cb", 1); + } + } + + parts { + part { + name: "bg"; + type: RECT; + description { + state: "default" 0.0; + color: 0 43 54 255; + } + } + part { + name: "elife"; + type: EXTERNAL; + source: "elife"; + + description { + state: "default" 0.0; + } + } + } + + // Get everything started at load + programs { + program { + name: "init"; + signal: "load"; + source: ""; + script { + clock_cb(0); + } + } + } + } +} diff --git a/m4/efl_binary.m4 b/m4/efl_binary.m4 new file mode 100644 index 0000000..c774688 --- /dev/null +++ b/m4/efl_binary.m4 @@ -0,0 +1,71 @@ +dnl Copyright (C) 2010 Vincent Torri +dnl That code is public domain and can be freely used or copied. + +dnl Macro that check if a binary is built or not + +dnl Usage: EFL_ENABLE_BIN(binary) +dnl Call AC_SUBST(BINARY_PRG) (BINARY is the uppercase of binary, - being transformed into _) +dnl Define have_binary (- is transformed into _) +dnl Define conditional BUILD_BINARY (BINARY is the uppercase of binary, - being transformed into _) + +AC_DEFUN([EFL_ENABLE_BIN], +[ + +m4_pushdef([UP], m4_translit([[$1]], [-a-z], [_A-Z]))dnl +m4_pushdef([DOWN], m4_translit([[$1]], [-A-Z], [_a-z]))dnl + +have_[]m4_defn([DOWN])="yes" + +dnl configure option + +AC_ARG_ENABLE([$1], + [AC_HELP_STRING([--disable-$1], [disable building of ]DOWN)], + [ + if test "x${enableval}" = "xyes" ; then + have_[]m4_defn([DOWN])="yes" + else + have_[]m4_defn([DOWN])="no" + fi + ]) + +AC_MSG_CHECKING([whether to build ]DOWN[ binary]) +AC_MSG_RESULT([$have_[]m4_defn([DOWN])]) + +if test "x$have_[]m4_defn([DOWN])" = "xyes"; then + UP[]_PRG=DOWN[${EXEEXT}] +fi + +AC_SUBST(UP[]_PRG) + +AM_CONDITIONAL(BUILD_[]UP, test "x$have_[]m4_defn([DOWN])" = "xyes") + +AS_IF([test "x$have_[]m4_defn([DOWN])" = "xyes"], [$2], [$3]) + +]) + + +dnl Macro that check if a binary is built or not + +dnl Usage: EFL_WITH_BIN(package, binary, default_value) +dnl Call AC_SUBST(_binary) (_binary is the lowercase of binary, - being transformed into _ by default, or the value set by the user) + +AC_DEFUN([EFL_WITH_BIN], +[ + +m4_pushdef([DOWN], m4_translit([[$2]], [-A-Z], [_a-z]))dnl + +dnl configure option + +AC_ARG_WITH([$2], + [AC_HELP_STRING([--with-$2=PATH], [specify a specific path to ]DOWN[ @<:@default=$3@:>@])], + [_efl_with_binary=${withval}], + [_efl_with_binary=$(pkg-config --variable=prefix $1)/bin/$3]) + +DOWN=${_efl_with_binary} +AC_MSG_NOTICE(DOWN[ set to ${_efl_with_binary}]) + +with_binary_[]m4_defn([DOWN])=${_efl_with_binary} + +AC_SUBST(DOWN) + +]) diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..7f6bd71 --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,29 @@ +MAINTAINERCLEANFILES = Makefile.in +INCLUDES = -I. \ + -I$(top_srcdir) \ + -I$(includedir) \ + @ELIFE_CFLAGS@ + + +pkgdir = $(datadir)/$(MODULE_ARCH) +pkg_LTLIBRARIES = module.la +module_la_SOURCES = \ + elife_evas_smart.c \ + elife_edje_external.c + +module_la_LIBADD = @ELIFE_LIBS@ +module_la_LDFLAGS = -module -avoid-version +module_la_DEPENDENCIES = $(top_builddir)/config.h + +bin_PROGRAMS = elife + +elife_SOURCES = \ + elife_evas_smart.c \ + elife.c +elife_CPPFLAGS = \ + @ELIFE_CFLAGS@ +elife_LDADD = \ + @ELIFE_LIBS@ + +clean-local: + rm -rf *~ diff --git a/src/elife.c b/src/elife.c new file mode 100644 index 0000000..c14fa9d --- /dev/null +++ b/src/elife.c @@ -0,0 +1,106 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "eenvaders_evas_smart.h" + +#define BG 0xff002b36 +#define FG 0xff839496 + +#define MIN(a,b) (((a)<(b))?(a):(b)) + +static struct { + Ecore_Evas *ee; + Evas *evas; + Evas_Coord w, h; + Evas_Object *bg; + Evas_Object *eenvaders; +} eenvaders_g; +#define _G eenvaders_g + +static void +resize_cb(Ecore_Evas *ee) +{ + int w, h; + + ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); + evas_object_resize(_G.bg, w, h); + evas_object_resize(_G.eenvaders, w, h); +} + +static Eina_Bool +timer_cb(void *data) +{ + Evas_Object *o = (Evas_Object *)data; + + evas_object_smart_callback_call(o, "refresh", NULL); + + return EINA_TRUE; +} + +int +main(void) +{ + unsigned int seedval; + int fd; + + if (!ecore_evas_init()) + return -1; + + _G.w = 600; + _G.h = 350; + + + /*open file */ + if ((fd = open("/dev/urandom", O_RDONLY)) < 0) { + perror(NULL); + exit(1); + } + if (read(fd, &seedval, sizeof(seedval)) != sizeof(seedval)) { + perror(NULL); + close(fd); + exit(1); + } + close(fd); + srand(seedval); + + _G.ee = ecore_evas_software_x11_new( + NULL, /* const char * disp_name */ + 0, /* Ecore_X_Window parent */ + 0, 0, _G.w, _G.h); + + ecore_evas_title_set(_G.ee, "EEnavders.fractal"); + ecore_evas_borderless_set(_G.ee, 0); + ecore_evas_show(_G.ee); + _G.evas = ecore_evas_get(_G.ee); + + _G.bg = evas_object_rectangle_add(_G.evas); + evas_object_color_set(_G.bg, + (BG >> 16) & 0xff, + (BG >> 8) & 0xff, + BG & 0xff, + BG >> 24); + evas_object_move(_G.bg, 0, 0); + evas_object_resize(_G.bg, _G.w, _G.h); + evas_object_show(_G.bg); + + _G.eenvaders = eenvaders_smart_new(_G.evas); + evas_object_resize(_G.eenvaders, _G.w, _G.h); + evas_object_show(_G.eenvaders); + + ecore_timer_add(3, timer_cb, _G.eenvaders); + + ecore_evas_callback_resize_set(_G.ee, &resize_cb); + + ecore_main_loop_begin(); + + ecore_evas_shutdown(); + ecore_shutdown(); + + return 0; +} diff --git a/src/elife_edje_external.c b/src/elife_edje_external.c new file mode 100644 index 0000000..4108194 --- /dev/null +++ b/src/elife_edje_external.c @@ -0,0 +1,192 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "eenvaders_evas_smart.h" + +/* Prototypes -{{{-*/ + +static Evas_Object * +eenvaders_ext_add(void *data, Evas *evas, Evas_Object *parent, + const Eina_List *params, const char *part_name); +static void +eenvaders_ext_state_set(void *data, Evas_Object *obj, + const void *from_params, + const void *to_params, float pos); +static void +eenvaders_ext_signal_emit(void *data, Evas_Object *obj, + const char *emission, const char *source); +static Eina_Bool +eenvaders_ext_param_set(void *data, Evas_Object *obj, + const Edje_External_Param *param); +static Eina_Bool +eenvaders_ext_param_get(void *data, const Evas_Object *obj, + Edje_External_Param *param); +static Evas_Object * +eenvaders_ext_content_get(void *data, const Evas_Object *obj, + const char *content); +static void* +eenvaders_ext_params_parse(void *data, Evas_Object *obj, + const Eina_List *params); +static void +eenvaders_ext_params_free(void *params); +static const char* +eenvaders_ext_label_get(void *data); +static const char* +eenvaders_ext_description_get(void *data); +static Evas_Object * +eenvaders_ext_icon_add(void *data, Evas *e); +static Evas_Object * +eenvaders_ext_preview_add(void *data, Evas *e); +static const char* +eenvaders_ext_translate(void *data, const char *orig); + +/* }}} */ +/* Globals -{{{-*/ + +static struct { + Edje_External_Type ext_type; +} eenvaders_g = { + .ext_type = { + .abi_version = EDJE_EXTERNAL_TYPE_ABI_VERSION, + .module = "eenvaders", + .module_name = "eenvaders", + .add = eenvaders_ext_add, + .state_set = eenvaders_ext_state_set, + .signal_emit = eenvaders_ext_signal_emit, + .param_set = eenvaders_ext_param_set, + .param_get = eenvaders_ext_param_get, + .content_get = eenvaders_ext_content_get, + .params_parse = eenvaders_ext_params_parse, + .params_free = eenvaders_ext_params_free, + .label_get = eenvaders_ext_label_get, + .description_get = eenvaders_ext_description_get, + .icon_add = eenvaders_ext_icon_add, + .preview_add = eenvaders_ext_preview_add, + .translate = eenvaders_ext_translate, + }, +}; +#define _G eenvaders_g + +/* }}} */ +/* Edje External -{{{-*/ + +static Evas_Object * +eenvaders_ext_add(void *data, Evas *evas, Evas_Object *parent, + const Eina_List *params, const char *part_name) +{ + return eenvaders_smart_new(evas); +} + +static void +eenvaders_ext_state_set(void *data, Evas_Object *obj, + const void *from_params, + const void *to_params, float pos) +{ +} + +static void +eenvaders_ext_signal_emit(void *data, Evas_Object *obj, + const char *emission, const char *source) +{ + evas_object_smart_callback_call(obj, emission, NULL); +} + +static Eina_Bool +eenvaders_ext_param_set(void *data, Evas_Object *obj, + const Edje_External_Param *param) +{ + return EINA_TRUE; +} + +static Eina_Bool +eenvaders_ext_param_get(void *data, const Evas_Object *obj, + Edje_External_Param *param) +{ + return EINA_TRUE; +} + +static Evas_Object * +eenvaders_ext_content_get(void *data, const Evas_Object *obj, + const char *content) +{ + return NULL; +} + +static void* +eenvaders_ext_params_parse(void *data, Evas_Object *obj, + const Eina_List *params) +{ + return NULL; +} + +static void +eenvaders_ext_params_free(void *params) +{ +} + +static const char* +eenvaders_ext_label_get(void *data) +{ + return NULL; +} + +static const char* +eenvaders_ext_description_get(void *data) +{ + return NULL; +} + +static Evas_Object * +eenvaders_ext_icon_add(void *data, Evas *e) +{ + return NULL; +} + +static Evas_Object * +eenvaders_ext_preview_add(void *data, Evas *e) +{ + return NULL; +} + +static const char* +eenvaders_ext_translate(void *data, const char *orig) +{ + return NULL; +} +/* }}} */ +/* Init/Shutdown -{{{-*/ + +Eina_Bool +eenvaders_init(void) +{ + unsigned int seedval = time(NULL); + int fd; + + if ((fd = open("/dev/random", O_RDONLY)) >= 0) { + read(fd, &seedval, sizeof(seedval)); + close(fd); + } + srand(seedval); + + edje_external_type_register("eenvaders", &_G.ext_type); + + return EINA_TRUE; +} + +void +eenvaders_shutdown(void) +{ + edje_external_type_unregister("eenvaders"); +} + +EINA_MODULE_INIT(eenvaders_init); +EINA_MODULE_SHUTDOWN(eenvaders_shutdown); + +/* }}} */ diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c new file mode 100644 index 0000000..935d4ae --- /dev/null +++ b/src/elife_evas_smart.c @@ -0,0 +1,304 @@ +#include + +#include "eenvaders_evas_smart.h" + +#define BG 0xff002b36 +#define FG 0xff839496 + +#define MIN(a,b) (((a)<(b))?(a):(b)) + +/* Prototypes -{{{-*/ +static Evas_Smart *_eenvaders_object_smart_get(void); +static Evas_Object *eenvaders_object_new(Evas *evas); +static void _eenvaders_object_del(Evas_Object *o); +static void _eenvaders_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y); +static void _eenvaders_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h); +static void _eenvaders_object_show(Evas_Object *o); +static void _eenvaders_object_hide(Evas_Object *o); +static void _eenvaders_object_color_set(Evas_Object *o, int r, int g, int b, int a); +static void _eenvaders_object_clip_set(Evas_Object *o, Evas_Object *clip); +static void _eenvaders_object_clip_unset(Evas_Object *o); + +static void +draw_eenvaders(Evas_Object *smart_obj, + int x, int y, int w, int h); +/* }}} */ +/* Globals -{{{-*/ + +static struct { + Evas_Smart_Class klass; +} eenvaders_evas_smart_g = { + .klass = { + .name = "eenvaders_object", + .version = EVAS_SMART_CLASS_VERSION, + .add = NULL, + .del = _eenvaders_object_del, + .move = _eenvaders_object_move, + .resize = _eenvaders_object_resize, + .show = NULL, + .hide = NULL, + .color_set = NULL, + .clip_set = NULL, + .clip_unset = NULL, + .calculate = NULL, + .member_add = NULL, + .member_del = NULL, + .parent = NULL, + .callbacks = NULL, + .interfaces = NULL, + .data = NULL, + }, +#define _G eenvaders_evas_smart_g +}; + +/* }}} */ +/* Eenvaders functions -{{{-*/ + +static void +eenvaders_mouse_down(void *data, + Evas *evas, + Evas_Object *child, + void *event_info) +{ + Evas_Coord x, y, w, h; + Evas_Event_Mouse_Up *evt = event_info; + Evas_Object *parent = data; + void *mem; + + x = evt->canvas.x; + y = evt->canvas.y; + + mem = evas_object_data_del(child, "m"); + if (!mem) + return; + + free(mem); + evas_object_geometry_get(child, &x, &y, &w, &h); + evas_object_smart_member_del(child); + evas_object_del(child); + draw_eenvaders(parent, x+3, y+3, w-3, h-3); +} + +static Evas_Object* +new_eenvader(Evas *evas, Evas_Object *smart_obj) +{ + Evas_Object *o = NULL; + uint16_t u = rand(); + int *mem = calloc(7 * 7, sizeof(int)); + + if (!mem) { + perror(NULL); + exit(1); + } + + for (int i = 0; i < 15; i++) { + if (u & (1 << i)) { + mem[7 + 7*(i/3) + 1 + i%3] = FG; + mem[7 + 7*(i/3) + 5 - i%3] = FG; + } + } + + o = evas_object_image_filled_add(evas); + evas_object_image_alpha_set(o, EINA_TRUE); + evas_object_image_fill_set(o, 0, 0, 7, 7); + evas_object_image_smooth_scale_set(o, EINA_FALSE); + evas_object_image_size_set (o, 7, 7); + evas_object_image_data_set(o, (void *) mem); + evas_object_data_set(o, "m", (void *) mem); + + evas_object_event_callback_add(o, + EVAS_CALLBACK_MOUSE_DOWN, + eenvaders_mouse_down, + smart_obj); + + return o; +} + +static int +square_ceil_7(int n) +{ + /* XXX: considering n >= 7 */ + int r = 1; + + n /= 7; + + while (n >>= 1) { + r <<= 1; + } + return r * 7; +} + +static void +draw_eenvaders(Evas_Object *smart_obj, + int x, int y, int w, int h) +{ + Evas_Object *o; + int d; + + if (w < 7 || h < 7) + return; + + d = square_ceil_7(MIN(w,h)); + + o = new_eenvader(evas_object_evas_get(smart_obj), smart_obj); + evas_object_resize(o, d, d); + evas_object_smart_member_add(o, smart_obj); + + switch(rand() & 3) { + case 0: + /* top-left */ + evas_object_move(o, x, y); + evas_object_show(o); + + draw_eenvaders(smart_obj, x+d, y, w-d, h); /* right */ + draw_eenvaders(smart_obj, x, y+d, d, h-d); /* bottom */ + break; + case 1: + /* top-right */ + evas_object_move(o, x+w-d, y); + evas_object_show(o); + + draw_eenvaders(smart_obj, x, y+d, w, h-d); /* bottom */ + draw_eenvaders(smart_obj, x, y, w-d, d); /* left */ + break; + case 2: + /* bottom-right */ + evas_object_move(o, x+w-d, y+h-d); + evas_object_show(o); + + draw_eenvaders(smart_obj, x, y, w-d, h); /* left */ + draw_eenvaders(smart_obj, x+w-d, y, d, h-d); /* top */ + break; + case 3: + /* bottom-left */ + evas_object_move(o, x, y+h-d); + evas_object_show(o); + + draw_eenvaders(smart_obj, x, y, w, h-d); /* top */ + draw_eenvaders(smart_obj, x+d, y+h-d, w-d, d); /* right */ + break; + } +} + +/* }}} */ +/* Smart Object -{{{-*/ + +Evas_Object * +eenvaders_smart_new(Evas *e) +{ + return eenvaders_object_new(e); +} + +static void +eenvaders_on_refresh(void *data, Evas_Object *o, void *event_info) +{ + Evas_Coord x, y, w, h; + Evas_Object *child; + void *mem; + Eina_List *list; + + list = evas_object_smart_members_get(o); + EINA_LIST_FREE(list, child) { + void *mem; + + mem = evas_object_data_del(child, "m"); + free(mem); + evas_object_event_callback_del(o, EVAS_CALLBACK_MOUSE_DOWN, + eenvaders_mouse_down); + evas_object_smart_member_del(child); + evas_object_del(child); + } + + evas_object_geometry_get(o, &x, &y, &w, &h); + draw_eenvaders(o, x, y, w, h); +} + +static Evas_Object * +eenvaders_object_new(Evas *evas) +{ + Evas_Object *eenvaders_object; + + eenvaders_object = evas_object_smart_add(evas, + _eenvaders_object_smart_get()); + evas_object_smart_callback_add(eenvaders_object, + "refresh", + eenvaders_on_refresh, + NULL); + + return eenvaders_object; +} + +static Evas_Smart * +_eenvaders_object_smart_get(void) +{ + static Evas_Smart *smart = NULL; + + if (smart) + return smart; + + smart = evas_smart_class_new(&_G.klass); + return smart; +} + +static void +_eenvaders_object_del(Evas_Object *o) +{ + Evas_Object *child; + void *mem; + Eina_List *list; + + list = evas_object_smart_members_get(o); + EINA_LIST_FREE(list, child) { + void *mem; + + evas_object_smart_member_del(child); + evas_object_del(child); + mem = evas_object_data_del(child, "m"); + free(mem); + + } +} + +static void +_eenvaders_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y) +{ + Evas_Coord orig_x, orig_y, dx, dy; + Eina_List *lst; + void *data; + + evas_object_geometry_get(o, &orig_x, &orig_y, NULL, NULL); + dx = x - orig_x; + dy = y - orig_y; + + lst = evas_object_smart_members_get(o); + EINA_LIST_FREE(lst, data) { + Evas_Object *child = data; + + evas_object_geometry_get(child, &orig_x, &orig_y, NULL, NULL); + evas_object_move(child, orig_x + dx, orig_y + dy); + } +} + +static void +_eenvaders_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) +{ + Evas_Coord x, y; + Evas_Object *child; + void *mem; + Eina_List *list; + + list = evas_object_smart_members_get(o); + EINA_LIST_FREE(list, child) { + void *mem; + + mem = evas_object_data_del(child, "m"); + free(mem); + evas_object_smart_member_del(child); + evas_object_del(child); + } + + evas_object_geometry_get(o, &x, &y, NULL, NULL); + draw_eenvaders(o, x, y, w, h); +} + +/* }}} */ diff --git a/src/elife_evas_smart.h b/src/elife_evas_smart.h new file mode 100644 index 0000000..65152f1 --- /dev/null +++ b/src/elife_evas_smart.h @@ -0,0 +1,8 @@ +#ifndef EENVADERS_SMART_H +#define EENVADERS_SMART_H +#include + +Evas_Object *eenvaders_smart_new(Evas *e); + +#endif + -- cgit v1.2.3-59-g8ed1b From b8b22efdce42d583b27d651db3ff11baa4a8261a Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 14 Oct 2012 16:38:22 +0200 Subject: just so it compiles --- src/elife.c | 2 +- src/elife_edje_external.c | 2 +- src/elife_evas_smart.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/elife.c b/src/elife.c index c14fa9d..0b34d72 100644 --- a/src/elife.c +++ b/src/elife.c @@ -7,7 +7,7 @@ #include #include -#include "eenvaders_evas_smart.h" +#include "elife_evas_smart.h" #define BG 0xff002b36 #define FG 0xff839496 diff --git a/src/elife_edje_external.c b/src/elife_edje_external.c index 4108194..099e204 100644 --- a/src/elife_edje_external.c +++ b/src/elife_edje_external.c @@ -8,7 +8,7 @@ #include #include -#include "eenvaders_evas_smart.h" +#include "elife_evas_smart.h" /* Prototypes -{{{-*/ diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 935d4ae..9c47e8c 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -1,6 +1,6 @@ #include -#include "eenvaders_evas_smart.h" +#include "elife_evas_smart.h" #define BG 0xff002b36 #define FG 0xff839496 -- cgit v1.2.3-59-g8ed1b From 5c273f97157291b7303da17e928663ff16ad9451 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 14 Oct 2012 20:08:32 +0200 Subject: preliminary work on elife. just compiles, does not run. --- src/elife.c | 16 +-- src/elife_edje_external.c | 100 +++++++------- src/elife_evas_smart.c | 331 +++++++++++++++++++--------------------------- src/elife_evas_smart.h | 6 +- 4 files changed, 198 insertions(+), 255 deletions(-) diff --git a/src/elife.c b/src/elife.c index 0b34d72..1656fab 100644 --- a/src/elife.c +++ b/src/elife.c @@ -19,9 +19,9 @@ static struct { Evas *evas; Evas_Coord w, h; Evas_Object *bg; - Evas_Object *eenvaders; -} eenvaders_g; -#define _G eenvaders_g + Evas_Object *elife; +} elife_g; +#define _G elife_g static void resize_cb(Ecore_Evas *ee) @@ -30,7 +30,7 @@ resize_cb(Ecore_Evas *ee) ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); evas_object_resize(_G.bg, w, h); - evas_object_resize(_G.eenvaders, w, h); + evas_object_resize(_G.elife, w, h); } static Eina_Bool @@ -89,11 +89,11 @@ main(void) evas_object_resize(_G.bg, _G.w, _G.h); evas_object_show(_G.bg); - _G.eenvaders = eenvaders_smart_new(_G.evas); - evas_object_resize(_G.eenvaders, _G.w, _G.h); - evas_object_show(_G.eenvaders); + _G.elife = elife_smart_new(_G.evas); + evas_object_resize(_G.elife, _G.w, _G.h); + evas_object_show(_G.elife); - ecore_timer_add(3, timer_cb, _G.eenvaders); + ecore_timer_add(3, timer_cb, _G.elife); ecore_evas_callback_resize_set(_G.ee, &resize_cb); diff --git a/src/elife_edje_external.c b/src/elife_edje_external.c index 099e204..14035d2 100644 --- a/src/elife_edje_external.c +++ b/src/elife_edje_external.c @@ -13,150 +13,150 @@ /* Prototypes -{{{-*/ static Evas_Object * -eenvaders_ext_add(void *data, Evas *evas, Evas_Object *parent, +elife_ext_add(void *data, Evas *evas, Evas_Object *parent, const Eina_List *params, const char *part_name); static void -eenvaders_ext_state_set(void *data, Evas_Object *obj, +elife_ext_state_set(void *data, Evas_Object *obj, const void *from_params, const void *to_params, float pos); static void -eenvaders_ext_signal_emit(void *data, Evas_Object *obj, +elife_ext_signal_emit(void *data, Evas_Object *obj, const char *emission, const char *source); static Eina_Bool -eenvaders_ext_param_set(void *data, Evas_Object *obj, +elife_ext_param_set(void *data, Evas_Object *obj, const Edje_External_Param *param); static Eina_Bool -eenvaders_ext_param_get(void *data, const Evas_Object *obj, +elife_ext_param_get(void *data, const Evas_Object *obj, Edje_External_Param *param); static Evas_Object * -eenvaders_ext_content_get(void *data, const Evas_Object *obj, +elife_ext_content_get(void *data, const Evas_Object *obj, const char *content); static void* -eenvaders_ext_params_parse(void *data, Evas_Object *obj, +elife_ext_params_parse(void *data, Evas_Object *obj, const Eina_List *params); static void -eenvaders_ext_params_free(void *params); +elife_ext_params_free(void *params); static const char* -eenvaders_ext_label_get(void *data); +elife_ext_label_get(void *data); static const char* -eenvaders_ext_description_get(void *data); +elife_ext_description_get(void *data); static Evas_Object * -eenvaders_ext_icon_add(void *data, Evas *e); +elife_ext_icon_add(void *data, Evas *e); static Evas_Object * -eenvaders_ext_preview_add(void *data, Evas *e); +elife_ext_preview_add(void *data, Evas *e); static const char* -eenvaders_ext_translate(void *data, const char *orig); +elife_ext_translate(void *data, const char *orig); /* }}} */ /* Globals -{{{-*/ static struct { Edje_External_Type ext_type; -} eenvaders_g = { +} elife_g = { .ext_type = { .abi_version = EDJE_EXTERNAL_TYPE_ABI_VERSION, - .module = "eenvaders", - .module_name = "eenvaders", - .add = eenvaders_ext_add, - .state_set = eenvaders_ext_state_set, - .signal_emit = eenvaders_ext_signal_emit, - .param_set = eenvaders_ext_param_set, - .param_get = eenvaders_ext_param_get, - .content_get = eenvaders_ext_content_get, - .params_parse = eenvaders_ext_params_parse, - .params_free = eenvaders_ext_params_free, - .label_get = eenvaders_ext_label_get, - .description_get = eenvaders_ext_description_get, - .icon_add = eenvaders_ext_icon_add, - .preview_add = eenvaders_ext_preview_add, - .translate = eenvaders_ext_translate, + .module = "elife", + .module_name = "elife", + .add = elife_ext_add, + .state_set = elife_ext_state_set, + .signal_emit = elife_ext_signal_emit, + .param_set = elife_ext_param_set, + .param_get = elife_ext_param_get, + .content_get = elife_ext_content_get, + .params_parse = elife_ext_params_parse, + .params_free = elife_ext_params_free, + .label_get = elife_ext_label_get, + .description_get = elife_ext_description_get, + .icon_add = elife_ext_icon_add, + .preview_add = elife_ext_preview_add, + .translate = elife_ext_translate, }, }; -#define _G eenvaders_g +#define _G elife_g /* }}} */ /* Edje External -{{{-*/ static Evas_Object * -eenvaders_ext_add(void *data, Evas *evas, Evas_Object *parent, +elife_ext_add(void *data, Evas *evas, Evas_Object *parent, const Eina_List *params, const char *part_name) { - return eenvaders_smart_new(evas); + return elife_smart_new(evas); } static void -eenvaders_ext_state_set(void *data, Evas_Object *obj, +elife_ext_state_set(void *data, Evas_Object *obj, const void *from_params, const void *to_params, float pos) { } static void -eenvaders_ext_signal_emit(void *data, Evas_Object *obj, +elife_ext_signal_emit(void *data, Evas_Object *obj, const char *emission, const char *source) { evas_object_smart_callback_call(obj, emission, NULL); } static Eina_Bool -eenvaders_ext_param_set(void *data, Evas_Object *obj, +elife_ext_param_set(void *data, Evas_Object *obj, const Edje_External_Param *param) { return EINA_TRUE; } static Eina_Bool -eenvaders_ext_param_get(void *data, const Evas_Object *obj, +elife_ext_param_get(void *data, const Evas_Object *obj, Edje_External_Param *param) { return EINA_TRUE; } static Evas_Object * -eenvaders_ext_content_get(void *data, const Evas_Object *obj, +elife_ext_content_get(void *data, const Evas_Object *obj, const char *content) { return NULL; } static void* -eenvaders_ext_params_parse(void *data, Evas_Object *obj, +elife_ext_params_parse(void *data, Evas_Object *obj, const Eina_List *params) { return NULL; } static void -eenvaders_ext_params_free(void *params) +elife_ext_params_free(void *params) { } static const char* -eenvaders_ext_label_get(void *data) +elife_ext_label_get(void *data) { return NULL; } static const char* -eenvaders_ext_description_get(void *data) +elife_ext_description_get(void *data) { return NULL; } static Evas_Object * -eenvaders_ext_icon_add(void *data, Evas *e) +elife_ext_icon_add(void *data, Evas *e) { return NULL; } static Evas_Object * -eenvaders_ext_preview_add(void *data, Evas *e) +elife_ext_preview_add(void *data, Evas *e) { return NULL; } static const char* -eenvaders_ext_translate(void *data, const char *orig) +elife_ext_translate(void *data, const char *orig) { return NULL; } @@ -164,7 +164,7 @@ eenvaders_ext_translate(void *data, const char *orig) /* Init/Shutdown -{{{-*/ Eina_Bool -eenvaders_init(void) +elife_init(void) { unsigned int seedval = time(NULL); int fd; @@ -175,18 +175,18 @@ eenvaders_init(void) } srand(seedval); - edje_external_type_register("eenvaders", &_G.ext_type); + edje_external_type_register("elife", &_G.ext_type); return EINA_TRUE; } void -eenvaders_shutdown(void) +elife_shutdown(void) { - edje_external_type_unregister("eenvaders"); + edje_external_type_unregister("elife"); } -EINA_MODULE_INIT(eenvaders_init); -EINA_MODULE_SHUTDOWN(eenvaders_shutdown); +EINA_MODULE_INIT(elife_init); +EINA_MODULE_SHUTDOWN(elife_shutdown); /* }}} */ diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 9c47e8c..9cbd6b7 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -1,4 +1,5 @@ #include +#include #include "elife_evas_smart.h" @@ -7,34 +8,28 @@ #define MIN(a,b) (((a)<(b))?(a):(b)) -/* Prototypes -{{{-*/ -static Evas_Smart *_eenvaders_object_smart_get(void); -static Evas_Object *eenvaders_object_new(Evas *evas); -static void _eenvaders_object_del(Evas_Object *o); -static void _eenvaders_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y); -static void _eenvaders_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h); -static void _eenvaders_object_show(Evas_Object *o); -static void _eenvaders_object_hide(Evas_Object *o); -static void _eenvaders_object_color_set(Evas_Object *o, int r, int g, int b, int a); -static void _eenvaders_object_clip_set(Evas_Object *o, Evas_Object *clip); -static void _eenvaders_object_clip_unset(Evas_Object *o); - -static void -draw_eenvaders(Evas_Object *smart_obj, - int x, int y, int w, int h); -/* }}} */ -/* Globals -{{{-*/ +static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, void *event_info); +static Evas_Smart *_elife_object_smart_get(void); +static Evas_Object *elife_object_new(Evas *evas); +static void _elife_object_del(Evas_Object *o); +static void _elife_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y); +static void _elife_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h); +static void _elife_object_show(Evas_Object *o); +static void _elife_object_hide(Evas_Object *o); +static void _elife_object_color_set(Evas_Object *o, int r, int g, int b, int a); +static void _elife_object_clip_set(Evas_Object *o, Evas_Object *clip); +static void _elife_object_clip_unset(Evas_Object *o); static struct { Evas_Smart_Class klass; -} eenvaders_evas_smart_g = { +} elife_evas_smart_g = { .klass = { - .name = "eenvaders_object", + .name = "elife_object", .version = EVAS_SMART_CLASS_VERSION, .add = NULL, - .del = _eenvaders_object_del, - .move = _eenvaders_object_move, - .resize = _eenvaders_object_resize, + .del = _elife_object_del, + .move = _elife_object_move, + .resize = _elife_object_resize, .show = NULL, .hide = NULL, .color_set = NULL, @@ -48,188 +43,154 @@ static struct { .interfaces = NULL, .data = NULL, }, -#define _G eenvaders_evas_smart_g +#define _G elife_evas_smart_g }; -/* }}} */ -/* Eenvaders functions -{{{-*/ - -static void -eenvaders_mouse_down(void *data, - Evas *evas, - Evas_Object *child, - void *event_info) -{ - Evas_Coord x, y, w, h; - Evas_Event_Mouse_Up *evt = event_info; - Evas_Object *parent = data; - void *mem; +struct cell { + Evas_Object *obj; + int age; +}; - x = evt->canvas.x; - y = evt->canvas.y; +struct grid { + struct cell ***grid; + Evas_Object *obj; + int w, h; + int age; +}; - mem = evas_object_data_del(child, "m"); - if (!mem) - return; +void * +xmalloc(size_t size) +{ + void *x; - free(mem); - evas_object_geometry_get(child, &x, &y, &w, &h); - evas_object_smart_member_del(child); - evas_object_del(child); - draw_eenvaders(parent, x+3, y+3, w-3, h-3); + x = malloc(size); + if (!x) + err(1, "Error: failed to allocate %d", size); + return x; } -static Evas_Object* -new_eenvader(Evas *evas, Evas_Object *smart_obj) +struct grid * +grid_new(Evas_Object *container, int w, int h) { - Evas_Object *o = NULL; - uint16_t u = rand(); - int *mem = calloc(7 * 7, sizeof(int)); - - if (!mem) { - perror(NULL); - exit(1); - } - - for (int i = 0; i < 15; i++) { - if (u & (1 << i)) { - mem[7 + 7*(i/3) + 1 + i%3] = FG; - mem[7 + 7*(i/3) + 5 - i%3] = FG; - } - } - - o = evas_object_image_filled_add(evas); - evas_object_image_alpha_set(o, EINA_TRUE); - evas_object_image_fill_set(o, 0, 0, 7, 7); - evas_object_image_smooth_scale_set(o, EINA_FALSE); - evas_object_image_size_set (o, 7, 7); - evas_object_image_data_set(o, (void *) mem); - evas_object_data_set(o, "m", (void *) mem); - - evas_object_event_callback_add(o, - EVAS_CALLBACK_MOUSE_DOWN, - eenvaders_mouse_down, - smart_obj); - - return o; + struct grid *g; + struct cell *cell; + Evas_Object *o; + int i, j; + + g = xmalloc(sizeof(struct grid)); + g->grid = xmalloc(sizeof(struct cell *) * w * h); + for (i=0; iobj = o; + cell->age = 0; + g->grid[i][j] = cell; + evas_object_smart_member_add(o, container); + } + } + g->obj = container; + g->w = w; + g->h = w; + g->age = 0; + + return g; } -static int -square_ceil_7(int n) +void +grid_del(struct grid *grid) { - /* XXX: considering n >= 7 */ - int r = 1; + /* program exits, OS will free */ +} - n /= 7; +int +grid_redraw(struct grid *grid) +{ + struct cell *cell; + int container_w, container_h, cell_w, cell_h; + int i,j; + Evas_Object *o; + + evas_object_geometry_get(grid->obj, &container_w, &container_h, NULL, NULL); + cell_w = container_w / grid->w; + cell_h = container_h / grid->h; + + for (i=0; iw; i++) { + for (j=0; jh; j++) { + cell = grid->grid[i][j]; + o = cell->obj; + evas_object_resize(o, cell_w, cell_h); + evas_object_image_fill_set(o, 0, 0, cell_w, cell_h); + evas_object_move(o, i*cell_w, j*cell_h); + evas_object_show(o); + } + } +} - while (n >>= 1) { - r <<= 1; - } - return r * 7; +int +grid_evolution(struct grid *grid) +{ + // XXX TODO } static void -draw_eenvaders(Evas_Object *smart_obj, - int x, int y, int w, int h) +cell_mouse_down(void *data, + Evas *evas, + Evas_Object *child, + void *event_info) { - Evas_Object *o; - int d; - - if (w < 7 || h < 7) - return; - - d = square_ceil_7(MIN(w,h)); - - o = new_eenvader(evas_object_evas_get(smart_obj), smart_obj); - evas_object_resize(o, d, d); - evas_object_smart_member_add(o, smart_obj); - - switch(rand() & 3) { - case 0: - /* top-left */ - evas_object_move(o, x, y); - evas_object_show(o); - - draw_eenvaders(smart_obj, x+d, y, w-d, h); /* right */ - draw_eenvaders(smart_obj, x, y+d, d, h-d); /* bottom */ - break; - case 1: - /* top-right */ - evas_object_move(o, x+w-d, y); - evas_object_show(o); - - draw_eenvaders(smart_obj, x, y+d, w, h-d); /* bottom */ - draw_eenvaders(smart_obj, x, y, w-d, d); /* left */ - break; - case 2: - /* bottom-right */ - evas_object_move(o, x+w-d, y+h-d); - evas_object_show(o); - - draw_eenvaders(smart_obj, x, y, w-d, h); /* left */ - draw_eenvaders(smart_obj, x+w-d, y, d, h-d); /* top */ - break; - case 3: - /* bottom-left */ - evas_object_move(o, x, y+h-d); - evas_object_show(o); - - draw_eenvaders(smart_obj, x, y, w, h-d); /* top */ - draw_eenvaders(smart_obj, x+d, y+h-d, w-d, d); /* right */ - break; - } -} + Evas_Coord x, y, w, h; + Evas_Event_Mouse_Up *evt = event_info; + struct cell *cell; -/* }}} */ -/* Smart Object -{{{-*/ + cell = data; +} Evas_Object * -eenvaders_smart_new(Evas *e) +elife_smart_new(Evas *e) { - return eenvaders_object_new(e); + return elife_object_new(e); } static void -eenvaders_on_refresh(void *data, Evas_Object *o, void *event_info) +elife_on_refresh(void *data, Evas_Object *o, void *event_info) { Evas_Coord x, y, w, h; Evas_Object *child; - void *mem; - Eina_List *list; - - list = evas_object_smart_members_get(o); - EINA_LIST_FREE(list, child) { - void *mem; - - mem = evas_object_data_del(child, "m"); - free(mem); - evas_object_event_callback_del(o, EVAS_CALLBACK_MOUSE_DOWN, - eenvaders_mouse_down); - evas_object_smart_member_del(child); - evas_object_del(child); - } + struct grid *grid; - evas_object_geometry_get(o, &x, &y, &w, &h); - draw_eenvaders(o, x, y, w, h); + grid_evolution(grid); } static Evas_Object * -eenvaders_object_new(Evas *evas) +elife_object_new(Evas *evas) { - Evas_Object *eenvaders_object; + Evas_Object *elife_object; - eenvaders_object = evas_object_smart_add(evas, - _eenvaders_object_smart_get()); - evas_object_smart_callback_add(eenvaders_object, + elife_object = evas_object_smart_add(evas, + _elife_object_smart_get()); + evas_object_smart_callback_add(elife_object, "refresh", - eenvaders_on_refresh, + elife_on_refresh, NULL); - return eenvaders_object; + return elife_object; } static Evas_Smart * -_eenvaders_object_smart_get(void) +_elife_object_smart_get(void) { static Evas_Smart *smart = NULL; @@ -241,29 +202,27 @@ _eenvaders_object_smart_get(void) } static void -_eenvaders_object_del(Evas_Object *o) +_elife_object_del(Evas_Object *o) { Evas_Object *child; - void *mem; + struct grid *grid; Eina_List *list; list = evas_object_smart_members_get(o); EINA_LIST_FREE(list, child) { - void *mem; - evas_object_smart_member_del(child); evas_object_del(child); - mem = evas_object_data_del(child, "m"); - free(mem); - } + grid = evas_object_data_del(child, "grid"); + grid_del(grid); } static void -_eenvaders_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y) +_elife_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y) { Evas_Coord orig_x, orig_y, dx, dy; Eina_List *lst; + Evas_Object *child; void *data; evas_object_geometry_get(o, &orig_x, &orig_y, NULL, NULL); @@ -272,33 +231,17 @@ _eenvaders_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y) lst = evas_object_smart_members_get(o); EINA_LIST_FREE(lst, data) { - Evas_Object *child = data; - + child = data; evas_object_geometry_get(child, &orig_x, &orig_y, NULL, NULL); evas_object_move(child, orig_x + dx, orig_y + dy); } } static void -_eenvaders_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) +_elife_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) { - Evas_Coord x, y; - Evas_Object *child; - void *mem; - Eina_List *list; + struct grid *grid; - list = evas_object_smart_members_get(o); - EINA_LIST_FREE(list, child) { - void *mem; - - mem = evas_object_data_del(child, "m"); - free(mem); - evas_object_smart_member_del(child); - evas_object_del(child); - } - - evas_object_geometry_get(o, &x, &y, NULL, NULL); - draw_eenvaders(o, x, y, w, h); + grid = evas_object_data_get(o, "grid"); + grid_redraw(grid); } - -/* }}} */ diff --git a/src/elife_evas_smart.h b/src/elife_evas_smart.h index 65152f1..b5a5b85 100644 --- a/src/elife_evas_smart.h +++ b/src/elife_evas_smart.h @@ -1,8 +1,8 @@ -#ifndef EENVADERS_SMART_H -#define EENVADERS_SMART_H +#ifndef ELIFE_SMART_H +#define ELIFE_SMART_H #include -Evas_Object *eenvaders_smart_new(Evas *e); +Evas_Object *elife_smart_new(Evas *e); #endif -- cgit v1.2.3-59-g8ed1b From 39a48dae6aac00d2bb289b80f754ee328b86b83a Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 3 Nov 2012 16:16:09 +0100 Subject: fix pointers --- src/elife_evas_smart.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 9cbd6b7..f7f53cf 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -3,9 +3,6 @@ #include "elife_evas_smart.h" -#define BG 0xff002b36 -#define FG 0xff839496 - #define MIN(a,b) (((a)<(b))?(a):(b)) static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, void *event_info); @@ -52,7 +49,7 @@ struct cell { }; struct grid { - struct cell ***grid; + struct cell **cells; Evas_Object *obj; int w, h; int age; @@ -78,10 +75,10 @@ grid_new(Evas_Object *container, int w, int h) int i, j; g = xmalloc(sizeof(struct grid)); - g->grid = xmalloc(sizeof(struct cell *) * w * h); + g->cells = xmalloc(sizeof(struct cell) * w * h); for (i=0; icells[(i*j) + j]); o = evas_object_image_filled_add(evas_object_evas_get(container)); if (!o) err(1, "Cannot create evas_object for cell"); @@ -97,7 +94,6 @@ grid_new(Evas_Object *container, int w, int h) cell); cell->obj = o; cell->age = 0; - g->grid[i][j] = cell; evas_object_smart_member_add(o, container); } } @@ -129,7 +125,7 @@ grid_redraw(struct grid *grid) for (i=0; iw; i++) { for (j=0; jh; j++) { - cell = grid->grid[i][j]; + cell = &(grid->cells[(i*j) + j]); o = cell->obj; evas_object_resize(o, cell_w, cell_h); evas_object_image_fill_set(o, 0, 0, cell_w, cell_h); @@ -178,9 +174,12 @@ static Evas_Object * elife_object_new(Evas *evas) { Evas_Object *elife_object; + struct grid *grid; elife_object = evas_object_smart_add(evas, _elife_object_smart_get()); + grid = grid_new(elife_object, 10, 10); + evas_object_data_set(elife_object, "grid", grid); evas_object_smart_callback_add(elife_object, "refresh", elife_on_refresh, -- cgit v1.2.3-59-g8ed1b From a0f2bbd180c96d1cf80dc82c96a497c54f05a7bf Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 3 Nov 2012 23:11:38 +0100 Subject: * use evas_object_rectangle instead of evas_object_image * add the basics of an evolution() --- src/elife_evas_smart.c | 72 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index f7f53cf..61014f8 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -49,7 +49,7 @@ struct cell { }; struct grid { - struct cell **cells; + struct cell *cells; Evas_Object *obj; int w, h; int age; @@ -78,22 +78,17 @@ grid_new(Evas_Object *container, int w, int h) g->cells = xmalloc(sizeof(struct cell) * w * h); for (i=0; icells[(i*j) + j]); - o = evas_object_image_filled_add(evas_object_evas_get(container)); + cell = &(g->cells[(i*w) + j]); + o = evas_object_rectangle_add(evas_object_evas_get(container)); if (!o) err(1, "Cannot create evas_object for cell"); - evas_object_image_alpha_set(o, EINA_TRUE); - evas_object_image_fill_set(o, 0, 0, 7, 7); - evas_object_image_smooth_scale_set(o, EINA_FALSE); - evas_object_image_size_set (o, 7, 7); - evas_object_image_data_set(o, (void *) cell); evas_object_data_set(o, "cell", (void *) cell); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, cell_mouse_down, cell); cell->obj = o; - cell->age = 0; + cell->age = 10; evas_object_smart_member_add(o, container); } } @@ -112,33 +107,70 @@ grid_del(struct grid *grid) } int -grid_redraw(struct grid *grid) +grid_redraw(struct grid *grid, int w, int h) { struct cell *cell; - int container_w, container_h, cell_w, cell_h; + int cell_w, cell_h; int i,j; Evas_Object *o; - evas_object_geometry_get(grid->obj, &container_w, &container_h, NULL, NULL); - cell_w = container_w / grid->w; - cell_h = container_h / grid->h; + cell_w = w / grid->w; + cell_h = h / grid->h; + printf("redraw: container %d %d cell %d %d\n", w, h, cell_w, cell_h); for (i=0; iw; i++) { for (j=0; jh; j++) { - cell = &(grid->cells[(i*j) + j]); + cell = &(grid->cells[(i*grid->w) + j]); o = cell->obj; evas_object_resize(o, cell_w, cell_h); - evas_object_image_fill_set(o, 0, 0, cell_w, cell_h); evas_object_move(o, i*cell_w, j*cell_h); + printf("redraw: %d %d %d %d\n", i*cell_w, j*cell_h, cell_w, cell_h); evas_object_show(o); } } } +static int +neighbours_count(struct cell *cell, struct grid *grid) +{ + int count; + + // XXX + count = 3; + return count; +} + int grid_evolution(struct grid *grid) { - // XXX TODO + struct cell *cell; + int container_w, container_h, cell_w, cell_h; + int i, j; + int r, g, b, a; + int neighbours; + Evas_Object *o; + + evas_object_geometry_get(grid->obj, &container_w, &container_h, NULL, NULL); + cell_w = container_w / grid->w; + cell_h = container_h / grid->h; + + for (i=0; iw; i++) { + for (j=0; jh; j++) { + cell = &(grid->cells[(i*grid->w) + j]); + o = cell->obj; + neighbours = neighbours_count(cell, grid); + if (neighbours > 3) + cell->age++; + else if (neighbours < 3) + cell->age--; + r = cell->age * 10; + g = (cell->age > 0) ? 250 : 0; + b = (cell->age > 0) ? 250 : 0; + a = 255; + evas_object_color_set(o, r, g, b, a); + printf("evolution: %d %d : %d\n", i, j, cell->age); + } + } } static void @@ -167,6 +199,8 @@ elife_on_refresh(void *data, Evas_Object *o, void *event_info) Evas_Object *child; struct grid *grid; + grid = evas_object_data_get(o, "grid"); + grid_evolution(grid); } @@ -224,6 +258,7 @@ _elife_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y) Evas_Object *child; void *data; + printf("oject_move: %d %d\n", x, y); evas_object_geometry_get(o, &orig_x, &orig_y, NULL, NULL); dx = x - orig_x; dy = y - orig_y; @@ -241,6 +276,7 @@ _elife_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) { struct grid *grid; + printf("oject_resize: %d %d\n", w, h); grid = evas_object_data_get(o, "grid"); - grid_redraw(grid); + grid_redraw(grid, w, h); } -- cgit v1.2.3-59-g8ed1b From 0a9d7b38c8fd4c1e1dbe501c849f68dd51361a93 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 02:39:21 +0100 Subject: fix evolution. bug free now :) population is evolving too much, need to add a limitation factor. --- src/elife_evas_smart.c | 82 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 19 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 61014f8..065e5a2 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -1,9 +1,19 @@ +/* elife - a game of life + * 2012, Laurent Ghigonis + */ + +/* TODO + * * GET_CELL() + */ + #include #include #include "elife_evas_smart.h" #define MIN(a,b) (((a)<(b))?(a):(b)) +#define NCELL_X 60 +#define NCELL_Y 60 static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, void *event_info); static Evas_Smart *_elife_object_smart_get(void); @@ -45,7 +55,8 @@ static struct { struct cell { Evas_Object *obj; - int age; + int age, newage; + int x, y; }; struct grid { @@ -88,7 +99,9 @@ grid_new(Evas_Object *container, int w, int h) cell_mouse_down, cell); cell->obj = o; - cell->age = 10; + cell->x = j; + cell->y = i; + cell->age = !(rand() % 6); evas_object_smart_member_add(o, container); } } @@ -106,6 +119,18 @@ grid_del(struct grid *grid) /* program exits, OS will free */ } +int +cell_redraw(struct cell *c) +{ + int r, g, b, a; + + r = c->age * 20; + g = (c->age > 0) ? 127 : 0; + b = (c->age > 0) ? 127 : 0; + a = 255; + evas_object_color_set(c->obj, r, g, b, a); +} + int grid_redraw(struct grid *grid, int w, int h) { @@ -124,7 +149,7 @@ grid_redraw(struct grid *grid, int w, int h) o = cell->obj; evas_object_resize(o, cell_w, cell_h); evas_object_move(o, i*cell_w, j*cell_h); - printf("redraw: %d %d %d %d\n", i*cell_w, j*cell_h, cell_w, cell_h); + cell_redraw(cell); evas_object_show(o); } } @@ -133,10 +158,25 @@ grid_redraw(struct grid *grid, int w, int h) static int neighbours_count(struct cell *cell, struct grid *grid) { + struct cell *ncell; + int m, n, cx, cy; int count; - // XXX - count = 3; + count = 0; + for (m=-1; m<=1; m++) { + for (n=-1; n<=1; n++) { + if (m == 0 && n == 0) + continue; + cx = cell->x + m; + cy = cell->y + n; + if (cx < 0 || cx >= grid->w || cy < 0 || cy >= grid->h) + continue; + ncell = &(grid->cells[(cy*grid->w) + cx]); + if (ncell->age > 0) + count++; + } + } + return count; } @@ -146,9 +186,7 @@ grid_evolution(struct grid *grid) struct cell *cell; int container_w, container_h, cell_w, cell_h; int i, j; - int r, g, b, a; int neighbours; - Evas_Object *o; evas_object_geometry_get(grid->obj, &container_w, &container_h, NULL, NULL); cell_w = container_w / grid->w; @@ -157,18 +195,22 @@ grid_evolution(struct grid *grid) for (i=0; iw; i++) { for (j=0; jh; j++) { cell = &(grid->cells[(i*grid->w) + j]); - o = cell->obj; neighbours = neighbours_count(cell, grid); - if (neighbours > 3) - cell->age++; - else if (neighbours < 3) - cell->age--; - r = cell->age * 10; - g = (cell->age > 0) ? 250 : 0; - b = (cell->age > 0) ? 250 : 0; - a = 255; - evas_object_color_set(o, r, g, b, a); - printf("evolution: %d %d : %d\n", i, j, cell->age); + if (neighbours == 4 || neighbours < 2) + cell->newage = 0; + else if (neighbours > 2) + cell->newage = cell->age + 1; + else + cell->newage = cell->age; + printf("evolution: %d %d n %d age %d newage %d\n", i, j, neighbours, cell->age, cell->newage); + } + } + + for (i=0; iw; i++) { + for (j=0; jh; j++) { + cell = &(grid->cells[(i*grid->w) + j]); + cell->age = cell->newage; + cell_redraw(cell); } } } @@ -184,6 +226,8 @@ cell_mouse_down(void *data, struct cell *cell; cell = data; + cell->age++; + cell_redraw(cell); } Evas_Object * @@ -212,7 +256,7 @@ elife_object_new(Evas *evas) elife_object = evas_object_smart_add(evas, _elife_object_smart_get()); - grid = grid_new(elife_object, 10, 10); + grid = grid_new(elife_object, NCELL_X, NCELL_Y); evas_object_data_set(elife_object, "grid", grid); evas_object_smart_callback_add(elife_object, "refresh", -- cgit v1.2.3-59-g8ed1b From 89be88961b9c797f9b00ef827ebebdc08ec34b6a Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 03:01:18 +0100 Subject: add debug option and set the grid size to 30x30 --- src/elife_evas_smart.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 065e5a2..5e1baf6 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -12,8 +12,9 @@ #include "elife_evas_smart.h" #define MIN(a,b) (((a)<(b))?(a):(b)) -#define NCELL_X 60 -#define NCELL_Y 60 +#define NCELL_X 30 +#define NCELL_Y 30 +#define DEBUG 0 static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, void *event_info); static Evas_Smart *_elife_object_smart_get(void); @@ -141,7 +142,8 @@ grid_redraw(struct grid *grid, int w, int h) cell_w = w / grid->w; cell_h = h / grid->h; - printf("redraw: container %d %d cell %d %d\n", w, h, cell_w, cell_h); + if (DEBUG) + printf("redraw: container %d %d cell %d %d\n", w, h, cell_w, cell_h); for (i=0; iw; i++) { for (j=0; jh; j++) { @@ -202,7 +204,8 @@ grid_evolution(struct grid *grid) cell->newage = cell->age + 1; else cell->newage = cell->age; - printf("evolution: %d %d n %d age %d newage %d\n", i, j, neighbours, cell->age, cell->newage); + if (DEBUG) + printf("evolution: %d %d n %d age %d newage %d\n", i, j, neighbours, cell->age, cell->newage); } } @@ -302,7 +305,8 @@ _elife_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y) Evas_Object *child; void *data; - printf("oject_move: %d %d\n", x, y); + if (DEBUG) + printf("oject_move: %d %d\n", x, y); evas_object_geometry_get(o, &orig_x, &orig_y, NULL, NULL); dx = x - orig_x; dy = y - orig_y; @@ -320,7 +324,8 @@ _elife_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) { struct grid *grid; - printf("oject_resize: %d %d\n", w, h); + if (DEBUG) + printf("oject_resize: %d %d\n", w, h); grid = evas_object_data_get(o, "grid"); grid_redraw(grid, w, h); } -- cgit v1.2.3-59-g8ed1b From df31b49db4a101f131849e034c4a6330424fe7a8 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 03:01:34 +0100 Subject: update the background every second --- data/elife.edc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/elife.edc b/data/elife.edc index be56255..34d26fe 100644 --- a/data/elife.edc +++ b/data/elife.edc @@ -9,7 +9,7 @@ collections { script { public clock_cb(unused) { emit("elife:refresh", "☃"); - timer(30, "clock_cb", 1); + timer(1, "clock_cb", 1); } } -- cgit v1.2.3-59-g8ed1b From 8db1b13d91bbd973a161d71120719e2a76213644 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 03:03:00 +0100 Subject: update elife every second --- src/elife.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elife.c b/src/elife.c index 1656fab..46f799b 100644 --- a/src/elife.c +++ b/src/elife.c @@ -93,7 +93,7 @@ main(void) evas_object_resize(_G.elife, _G.w, _G.h); evas_object_show(_G.elife); - ecore_timer_add(3, timer_cb, _G.elife); + ecore_timer_add(1, timer_cb, _G.elife); ecore_evas_callback_resize_set(_G.ee, &resize_cb); -- cgit v1.2.3-59-g8ed1b From 140898a02071d2b37ce26ff7dc7ac88bfad56afd Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 03:09:34 +0100 Subject: die more often ! and update reference comments --- src/elife_evas_smart.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 5e1baf6..84701d8 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -1,8 +1,10 @@ -/* elife - a game of life - * 2012, Laurent Ghigonis +/* + * elife - Game of life / Living graphic + * 2012 Laurent Ghigonis */ -/* TODO +/* + * TODO * * GET_CELL() */ @@ -198,7 +200,7 @@ grid_evolution(struct grid *grid) for (j=0; jh; j++) { cell = &(grid->cells[(i*grid->w) + j]); neighbours = neighbours_count(cell, grid); - if (neighbours == 4 || neighbours < 2) + if (neighbours == 4 || neighbours == 5 || neighbours < 2) cell->newage = 0; else if (neighbours > 2) cell->newage = cell->age + 1; -- cgit v1.2.3-59-g8ed1b From a2da241989e4d8372753be59ba955e75d2e82fcf Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 03:20:20 +0100 Subject: black background --- data/elife.edc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/elife.edc b/data/elife.edc index 34d26fe..828704c 100644 --- a/data/elife.edc +++ b/data/elife.edc @@ -19,7 +19,7 @@ collections { type: RECT; description { state: "default" 0.0; - color: 0 43 54 255; + color: 0 0 0 255; } } part { -- cgit v1.2.3-59-g8ed1b From 7a5fbe026e34dc5afa70d309917c4b36d5565774 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 03:46:07 +0100 Subject: better colors --- src/elife_evas_smart.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 84701d8..8b35b87 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -127,9 +127,9 @@ cell_redraw(struct cell *c) { int r, g, b, a; - r = c->age * 20; - g = (c->age > 0) ? 127 : 0; - b = (c->age > 0) ? 127 : 0; + r = (c->age > 0) ? 128 : 0; + g = (c->age > 0) ? (33 + c->age * 7) : 0; + b = (c->age > 0) ? 0 : 0; a = 255; evas_object_color_set(c->obj, r, g, b, a); } -- cgit v1.2.3-59-g8ed1b From 5bb6b53e384330fc4294aaf4185f9fc02a7bd1ab Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 03:59:10 +0100 Subject: improve evolution --- src/elife_evas_smart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 8b35b87..10ec425 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -200,9 +200,9 @@ grid_evolution(struct grid *grid) for (j=0; jh; j++) { cell = &(grid->cells[(i*grid->w) + j]); neighbours = neighbours_count(cell, grid); - if (neighbours == 4 || neighbours == 5 || neighbours < 2) + if (neighbours == 4 || neighbours < 2) cell->newage = 0; - else if (neighbours > 2) + else if (neighbours > 2 && neighbours != 5) cell->newage = cell->age + 1; else cell->newage = cell->age; -- cgit v1.2.3-59-g8ed1b From 02c03ffeddeb0e5244c337dcecdae899d67c03ea Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 04:06:53 +0100 Subject: imcrease default size --- src/elife_evas_smart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 10ec425..8307931 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -14,8 +14,8 @@ #include "elife_evas_smart.h" #define MIN(a,b) (((a)<(b))?(a):(b)) -#define NCELL_X 30 -#define NCELL_Y 30 +#define NCELL_X 40 +#define NCELL_Y 40 #define DEBUG 0 static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, void *event_info); -- cgit v1.2.3-59-g8ed1b From 9e5542d599be06ea4137a1e83ff82215c10cbfc7 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 17:59:31 +0100 Subject: various improvements * add hability to have multiple modes for cells evolution * implement Conway's Game of Life mode * setup injection of known patterns at random time * add a CELL_GET() macro and use it --- src/elife_evas_smart.c | 156 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 125 insertions(+), 31 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 8307931..4239095 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -5,7 +5,8 @@ /* * TODO - * * GET_CELL() + * static functions + * define functions headers + reorg order */ #include @@ -13,11 +14,14 @@ #include "elife_evas_smart.h" -#define MIN(a,b) (((a)<(b))?(a):(b)) #define NCELL_X 40 #define NCELL_Y 40 +#define INJECT_PROBA 30 #define DEBUG 0 +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define CELL_GET(grid, x, y) &(grid->cells[(y*grid->w) + x]) + static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, void *event_info); static Evas_Smart *_elife_object_smart_get(void); static Evas_Object *elife_object_new(Evas *evas); @@ -56,6 +60,38 @@ static struct { #define _G elife_evas_smart_g }; +typedef struct lifepattern_s { + const int w; + const int h; + const char *pat; +} lifepattern_s; + +enum lifepattern_t { + ELIFE_PAT_BEEHIVE = 0, + ELIFE_PAT_BOAT = 1, + ELIFE_PAT_SHIP = 2, + ELIFE_PAT_LOAF = 3, + ELIFE_PAT_QUEENBEE = 4, + ELIFE_PAT_GLIDER = 5, + ELIFE_PAT_LWSS = 6, +}; +lifepattern_s lifepatterns[] = { + [ELIFE_PAT_BEEHIVE] = {3, 4, "010101101010"}, + [ELIFE_PAT_BOAT] = {3, 3, "010101011"}, + [ELIFE_PAT_SHIP] = {3, 3, "110101011"}, + [ELIFE_PAT_LOAF] = {4, 4, "0110100101010010"}, + [ELIFE_PAT_QUEENBEE] = {4, 7, "1100001000010001000100101100"}, + [ELIFE_PAT_GLIDER] = {3, 3, "010011101"}, + [ELIFE_PAT_LWSS] = {5, 4, "10010000011000101111"}, +}; +#define PATTERN_COUNT 7 + +enum lifemode { + ELIFE_MODE_CONWAY, + ELIFE_MODE_CONWAY_GROW, + ELIFE_MODE_LORAN_CIVILISATION, +}; + struct cell { Evas_Object *obj; int age, newage; @@ -67,6 +103,7 @@ struct grid { Evas_Object *obj; int w, h; int age; + enum lifemode mode; }; void * @@ -80,8 +117,35 @@ xmalloc(size_t size) return x; } +static void +inject_pattern(struct grid *grid) +{ + struct cell *cell; + enum lifepattern_t npat; + lifepattern_s *pat; + int x, y, cx, cy; + int i, j; + + npat = rand() % PATTERN_COUNT; + if (DEBUG) + printf("inject_pattern: %d\n", npat); + pat = &lifepatterns[npat]; + x = rand() % (grid->w - pat->w); + y = rand() % (grid->h - pat->h); + for (j=0; jh; j++) { + for (i=0; iw; i++) { + cx = x + i; + cy = y + j; + if (cx >= grid->w || cy >= grid->h) + continue; + cell = CELL_GET(grid, cx, cy); + cell->newage = (pat->pat[pat->w*j + i] - '0') * 27; + } + } +} + struct grid * -grid_new(Evas_Object *container, int w, int h) +grid_new(Evas_Object *container, int w, int h, enum lifemode mode) { struct grid *g; struct cell *cell; @@ -89,10 +153,15 @@ grid_new(Evas_Object *container, int w, int h) int i, j; g = xmalloc(sizeof(struct grid)); + g->obj = container; + g->w = w; + g->h = w; + g->age = 0; + g->mode = mode; g->cells = xmalloc(sizeof(struct cell) * w * h); - for (i=0; icells[(i*w) + j]); + for (j=0; jobj = o; - cell->x = j; - cell->y = i; + cell->x = i; + cell->y = j; cell->age = !(rand() % 6); evas_object_smart_member_add(o, container); } } - g->obj = container; - g->w = w; - g->h = w; - g->age = 0; return g; } @@ -147,9 +212,9 @@ grid_redraw(struct grid *grid, int w, int h) if (DEBUG) printf("redraw: container %d %d cell %d %d\n", w, h, cell_w, cell_h); - for (i=0; iw; i++) { - for (j=0; jh; j++) { - cell = &(grid->cells[(i*grid->w) + j]); + for (j=0; jh; j++) { + for (i=0; iw; i++) { + cell = CELL_GET(grid, i, j); o = cell->obj; evas_object_resize(o, cell_w, cell_h); evas_object_move(o, i*cell_w, j*cell_h); @@ -167,15 +232,15 @@ neighbours_count(struct cell *cell, struct grid *grid) int count; count = 0; - for (m=-1; m<=1; m++) { - for (n=-1; n<=1; n++) { + for (n=-1; n<=1; n++) { + for (m=-1; m<=1; m++) { if (m == 0 && n == 0) continue; cx = cell->x + m; cy = cell->y + n; if (cx < 0 || cx >= grid->w || cy < 0 || cy >= grid->h) continue; - ncell = &(grid->cells[(cy*grid->w) + cx]); + ncell = CELL_GET(grid, cx, cy); if (ncell->age > 0) count++; } @@ -196,28 +261,57 @@ grid_evolution(struct grid *grid) cell_w = container_w / grid->w; cell_h = container_h / grid->h; - for (i=0; iw; i++) { - for (j=0; jh; j++) { - cell = &(grid->cells[(i*grid->w) + j]); + for (j=0; jh; j++) { + for (i=0; iw; i++) { + cell = CELL_GET(grid, i, j); neighbours = neighbours_count(cell, grid); - if (neighbours == 4 || neighbours < 2) - cell->newage = 0; - else if (neighbours > 2 && neighbours != 5) - cell->newage = cell->age + 1; - else - cell->newage = cell->age; + switch (grid->mode) { + case ELIFE_MODE_CONWAY: + if (cell->age == 0 && neighbours == 3) + cell->newage = 1; + else if (cell->age > 0 && (neighbours == 2 || neighbours == 3)) + cell->newage = cell->age; + else + cell->newage = 0; + break; + case ELIFE_MODE_CONWAY_GROW: + if (cell->age == 0 && neighbours == 3) + cell->newage = 1; + else if (cell->age > 0 && (neighbours == 2 || neighbours == 3)) + cell->newage = cell->age + 1; + else + cell->newage = 0; + break; + case ELIFE_MODE_LORAN_CIVILISATION: + if (neighbours == 4 || neighbours < 2) + cell->newage = 0; + else if (neighbours > 2 && neighbours != 5) + cell->newage = cell->age + 1; + else if (neighbours == 2 && cell->age > 1) + cell->newage = 0; + else + cell->newage = cell->age; + if (cell->age > 100) + cell->newage = 0; + break; + } if (DEBUG) printf("evolution: %d %d n %d age %d newage %d\n", i, j, neighbours, cell->age, cell->newage); } } - for (i=0; iw; i++) { - for (j=0; jh; j++) { - cell = &(grid->cells[(i*grid->w) + j]); + if (rand() % INJECT_PROBA == 0) + inject_pattern(grid); + + for (j=0; jh; j++) { + for (i=0; iw; i++) { + cell = CELL_GET(grid, i, j); cell->age = cell->newage; cell_redraw(cell); } } + + grid->age++; } static void @@ -261,7 +355,7 @@ elife_object_new(Evas *evas) elife_object = evas_object_smart_add(evas, _elife_object_smart_get()); - grid = grid_new(elife_object, NCELL_X, NCELL_Y); + grid = grid_new(elife_object, NCELL_X, NCELL_Y, ELIFE_MODE_CONWAY_GROW); evas_object_data_set(elife_object, "grid", grid); evas_object_smart_callback_add(elife_object, "refresh", -- cgit v1.2.3-59-g8ed1b From 04c2e82de472b6077ef8f0f759301379aabc4273 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 18:17:06 +0100 Subject: cleanup * add function headers for all functions * set some function as static * reorganise some functions order in the file --- src/elife_evas_smart.c | 305 ++++++++++++++++++++++++++----------------------- 1 file changed, 161 insertions(+), 144 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 4239095..e158229 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -5,8 +5,7 @@ /* * TODO - * static functions - * define functions headers + reorg order + * */ #include @@ -22,44 +21,6 @@ #define MIN(a,b) (((a)<(b))?(a):(b)) #define CELL_GET(grid, x, y) &(grid->cells[(y*grid->w) + x]) -static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, void *event_info); -static Evas_Smart *_elife_object_smart_get(void); -static Evas_Object *elife_object_new(Evas *evas); -static void _elife_object_del(Evas_Object *o); -static void _elife_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y); -static void _elife_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h); -static void _elife_object_show(Evas_Object *o); -static void _elife_object_hide(Evas_Object *o); -static void _elife_object_color_set(Evas_Object *o, int r, int g, int b, int a); -static void _elife_object_clip_set(Evas_Object *o, Evas_Object *clip); -static void _elife_object_clip_unset(Evas_Object *o); - -static struct { - Evas_Smart_Class klass; -} elife_evas_smart_g = { - .klass = { - .name = "elife_object", - .version = EVAS_SMART_CLASS_VERSION, - .add = NULL, - .del = _elife_object_del, - .move = _elife_object_move, - .resize = _elife_object_resize, - .show = NULL, - .hide = NULL, - .color_set = NULL, - .clip_set = NULL, - .clip_unset = NULL, - .calculate = NULL, - .member_add = NULL, - .member_del = NULL, - .parent = NULL, - .callbacks = NULL, - .interfaces = NULL, - .data = NULL, - }, -#define _G elife_evas_smart_g -}; - typedef struct lifepattern_s { const int w; const int h; @@ -106,6 +67,60 @@ struct grid { enum lifemode mode; }; +static struct grid *grid_new(Evas_Object *container, + int w, int h, enum lifemode mode); +static void grid_del(struct grid *grid); +static int grid_evolution(struct grid *grid); +static void grid_inject_pattern(struct grid *grid); +static int grid_redraw(struct grid *grid, int w, int h); +static int cell_neighbours_count(struct cell *cell, struct grid *grid); +static int cell_redraw(struct cell *c); + +Evas_Object *elife_smart_new(Evas *e); +static void elife_on_refresh(void *data, Evas_Object *o, + void *event_info); +static Evas_Object *elife_object_new(Evas *evas); +static Evas_Object *elife_object_new(Evas *evas); +static Evas_Smart *_elife_object_smart_get(void); +static void _elife_object_del(Evas_Object *o); +static void _elife_object_move(Evas_Object *o, + Evas_Coord x, Evas_Coord y); +static void _elife_object_resize(Evas_Object *o, + Evas_Coord w, Evas_Coord h); +/*static void _elife_object_show(Evas_Object *o); +static void _elife_object_hide(Evas_Object *o); +static void _elife_object_color_set(Evas_Object *o, int r, int g, int b, int a); +static void _elife_object_clip_set(Evas_Object *o, Evas_Object *clip); +static void _elife_object_clip_unset(Evas_Object *o); */ +static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, + void *event_info); + +static struct { + Evas_Smart_Class klass; +} elife_evas_smart_g = { + .klass = { + .name = "elife_object", + .version = EVAS_SMART_CLASS_VERSION, + .add = NULL, + .del = _elife_object_del, + .move = _elife_object_move, + .resize = _elife_object_resize, + .show = NULL, + .hide = NULL, + .color_set = NULL, + .clip_set = NULL, + .clip_unset = NULL, + .calculate = NULL, + .member_add = NULL, + .member_del = NULL, + .parent = NULL, + .callbacks = NULL, + .interfaces = NULL, + .data = NULL, + }, +#define _G elife_evas_smart_g +}; + void * xmalloc(size_t size) { @@ -117,34 +132,7 @@ xmalloc(size_t size) return x; } -static void -inject_pattern(struct grid *grid) -{ - struct cell *cell; - enum lifepattern_t npat; - lifepattern_s *pat; - int x, y, cx, cy; - int i, j; - - npat = rand() % PATTERN_COUNT; - if (DEBUG) - printf("inject_pattern: %d\n", npat); - pat = &lifepatterns[npat]; - x = rand() % (grid->w - pat->w); - y = rand() % (grid->h - pat->h); - for (j=0; jh; j++) { - for (i=0; iw; i++) { - cx = x + i; - cy = y + j; - if (cx >= grid->w || cy >= grid->h) - continue; - cell = CELL_GET(grid, cx, cy); - cell->newage = (pat->pat[pat->w*j + i] - '0') * 27; - } - } -} - -struct grid * +static struct grid * grid_new(Evas_Object *container, int w, int h, enum lifemode mode) { struct grid *g; @@ -181,75 +169,13 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) return g; } -void +static void grid_del(struct grid *grid) { /* program exits, OS will free */ } -int -cell_redraw(struct cell *c) -{ - int r, g, b, a; - - r = (c->age > 0) ? 128 : 0; - g = (c->age > 0) ? (33 + c->age * 7) : 0; - b = (c->age > 0) ? 0 : 0; - a = 255; - evas_object_color_set(c->obj, r, g, b, a); -} - -int -grid_redraw(struct grid *grid, int w, int h) -{ - struct cell *cell; - int cell_w, cell_h; - int i,j; - Evas_Object *o; - - cell_w = w / grid->w; - cell_h = h / grid->h; - if (DEBUG) - printf("redraw: container %d %d cell %d %d\n", w, h, cell_w, cell_h); - - for (j=0; jh; j++) { - for (i=0; iw; i++) { - cell = CELL_GET(grid, i, j); - o = cell->obj; - evas_object_resize(o, cell_w, cell_h); - evas_object_move(o, i*cell_w, j*cell_h); - cell_redraw(cell); - evas_object_show(o); - } - } -} - static int -neighbours_count(struct cell *cell, struct grid *grid) -{ - struct cell *ncell; - int m, n, cx, cy; - int count; - - count = 0; - for (n=-1; n<=1; n++) { - for (m=-1; m<=1; m++) { - if (m == 0 && n == 0) - continue; - cx = cell->x + m; - cy = cell->y + n; - if (cx < 0 || cx >= grid->w || cy < 0 || cy >= grid->h) - continue; - ncell = CELL_GET(grid, cx, cy); - if (ncell->age > 0) - count++; - } - } - - return count; -} - -int grid_evolution(struct grid *grid) { struct cell *cell; @@ -264,7 +190,7 @@ grid_evolution(struct grid *grid) for (j=0; jh; j++) { for (i=0; iw; i++) { cell = CELL_GET(grid, i, j); - neighbours = neighbours_count(cell, grid); + neighbours = cell_neighbours_count(cell, grid); switch (grid->mode) { case ELIFE_MODE_CONWAY: if (cell->age == 0 && neighbours == 3) @@ -296,12 +222,13 @@ grid_evolution(struct grid *grid) break; } if (DEBUG) - printf("evolution: %d %d n %d age %d newage %d\n", i, j, neighbours, cell->age, cell->newage); + printf("evolution: %d %d n %d age %d newage %d\n", i, j, + neighbours, cell->age, cell->newage); } } if (rand() % INJECT_PROBA == 0) - inject_pattern(grid); + grid_inject_pattern(grid); for (j=0; jh; j++) { for (i=0; iw; i++) { @@ -315,18 +242,92 @@ grid_evolution(struct grid *grid) } static void -cell_mouse_down(void *data, - Evas *evas, - Evas_Object *child, - void *event_info) +grid_inject_pattern(struct grid *grid) { - Evas_Coord x, y, w, h; - Evas_Event_Mouse_Up *evt = event_info; - struct cell *cell; + struct cell *cell; + enum lifepattern_t npat; + lifepattern_s *pat; + int x, y, cx, cy; + int i, j; - cell = data; - cell->age++; - cell_redraw(cell); + npat = rand() % PATTERN_COUNT; + if (DEBUG) + printf("grid_inject_pattern: %d\n", npat); + pat = &lifepatterns[npat]; + x = rand() % (grid->w - pat->w); + y = rand() % (grid->h - pat->h); + for (j=0; jh; j++) { + for (i=0; iw; i++) { + cx = x + i; + cy = y + j; + if (cx >= grid->w || cy >= grid->h) + continue; + cell = CELL_GET(grid, cx, cy); + cell->newage = (pat->pat[pat->w*j + i] - '0') * 27; + } + } +} + +static int +grid_redraw(struct grid *grid, int w, int h) +{ + struct cell *cell; + int cell_w, cell_h; + int i,j; + Evas_Object *o; + + cell_w = w / grid->w; + cell_h = h / grid->h; + if (DEBUG) + printf("redraw: container %d %d cell %d %d\n", w, h, cell_w, cell_h); + + for (j=0; jh; j++) { + for (i=0; iw; i++) { + cell = CELL_GET(grid, i, j); + o = cell->obj; + evas_object_resize(o, cell_w, cell_h); + evas_object_move(o, i*cell_w, j*cell_h); + cell_redraw(cell); + evas_object_show(o); + } + } +} + +static int +cell_neighbours_count(struct cell *cell, struct grid *grid) +{ + struct cell *ncell; + int m, n, cx, cy; + int count; + + count = 0; + for (n=-1; n<=1; n++) { + for (m=-1; m<=1; m++) { + if (m == 0 && n == 0) + continue; + cx = cell->x + m; + cy = cell->y + n; + if (cx < 0 || cx >= grid->w || cy < 0 || cy >= grid->h) + continue; + ncell = CELL_GET(grid, cx, cy); + if (ncell->age > 0) + count++; + } + } + + return count; +} + +static int +cell_redraw(struct cell *c) +{ + int r, g, b, a; + + r = (c->age > 0) ? 128 : 0; + g = (c->age > 0) ? (33 + c->age * 7) : 0; + b = (c->age > 0) ? 0 : 0; + a = 255; + evas_object_color_set(c->obj, r, g, b, a); } Evas_Object * @@ -425,3 +426,19 @@ _elife_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) grid = evas_object_data_get(o, "grid"); grid_redraw(grid, w, h); } + +static void +cell_mouse_down(void *data, + Evas *evas, + Evas_Object *child, + void *event_info) +{ + Evas_Coord x, y, w, h; + Evas_Event_Mouse_Up *evt = event_info; + struct cell *cell; + + cell = data; + cell->age++; + cell_redraw(cell); +} + -- cgit v1.2.3-59-g8ed1b From 2eac8b9c1681e3892dd09e2196cb234b13dd52cb Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 18:19:14 +0100 Subject: fix indent --- src/elife_evas_smart.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index e158229..7068e88 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -80,13 +80,12 @@ Evas_Object *elife_smart_new(Evas *e); static void elife_on_refresh(void *data, Evas_Object *o, void *event_info); static Evas_Object *elife_object_new(Evas *evas); -static Evas_Object *elife_object_new(Evas *evas); -static Evas_Smart *_elife_object_smart_get(void); -static void _elife_object_del(Evas_Object *o); -static void _elife_object_move(Evas_Object *o, - Evas_Coord x, Evas_Coord y); -static void _elife_object_resize(Evas_Object *o, - Evas_Coord w, Evas_Coord h); +static Evas_Smart *_elife_object_smart_get(void); +static void _elife_object_del(Evas_Object *o); +static void _elife_object_move(Evas_Object *o, + Evas_Coord x, Evas_Coord y); +static void _elife_object_resize(Evas_Object *o, + Evas_Coord w, Evas_Coord h); /*static void _elife_object_show(Evas_Object *o); static void _elife_object_hide(Evas_Object *o); static void _elife_object_color_set(Evas_Object *o, int r, int g, int b, int a); -- cgit v1.2.3-59-g8ed1b From 7ad467e961b3436424450e93264b108d031868a3 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 18:28:59 +0100 Subject: add license --- src/elife_evas_smart.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 7068e88..a3fda6c 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -3,6 +3,22 @@ * 2012 Laurent Ghigonis */ +/* + * Copyright (c) 2012 Laurent Ghigonis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + /* * TODO * -- cgit v1.2.3-59-g8ed1b From 50ee8b1729b53cf233900bcaeac405c14935e96f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 18:31:17 +0100 Subject: move around function --- src/elife_evas_smart.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index a3fda6c..673bf8e 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -91,6 +91,8 @@ static void grid_inject_pattern(struct grid *grid); static int grid_redraw(struct grid *grid, int w, int h); static int cell_neighbours_count(struct cell *cell, struct grid *grid); static int cell_redraw(struct cell *c); +static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, + void *event_info); Evas_Object *elife_smart_new(Evas *e); static void elife_on_refresh(void *data, Evas_Object *o, @@ -107,8 +109,6 @@ static void _elife_object_hide(Evas_Object *o); static void _elife_object_color_set(Evas_Object *o, int r, int g, int b, int a); static void _elife_object_clip_set(Evas_Object *o, Evas_Object *clip); static void _elife_object_clip_unset(Evas_Object *o); */ -static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, - void *event_info); static struct { Evas_Smart_Class klass; @@ -345,6 +345,21 @@ cell_redraw(struct cell *c) evas_object_color_set(c->obj, r, g, b, a); } +static void +cell_mouse_down(void *data, + Evas *evas, + Evas_Object *child, + void *event_info) +{ + Evas_Coord x, y, w, h; + Evas_Event_Mouse_Up *evt = event_info; + struct cell *cell; + + cell = data; + cell->age++; + cell_redraw(cell); +} + Evas_Object * elife_smart_new(Evas *e) { @@ -442,18 +457,3 @@ _elife_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) grid_redraw(grid, w, h); } -static void -cell_mouse_down(void *data, - Evas *evas, - Evas_Object *child, - void *event_info) -{ - Evas_Coord x, y, w, h; - Evas_Event_Mouse_Up *evt = event_info; - struct cell *cell; - - cell = data; - cell->age++; - cell_redraw(cell); -} - -- cgit v1.2.3-59-g8ed1b From b0be1fab3b8cc737110ce74bce5333359633acc2 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 18:33:02 +0100 Subject: add version and thank Boris ! --- README | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README b/README index 8847b7e..c8550e2 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ elife - Game of life / Living graphic -2012 Laurent Ghigonis +v1.0 Packaging and general structure from EEnvader.fractal by Boris Faure - +Many thanks to you Boris ! -- cgit v1.2.3-59-g8ed1b From 30c76393b144880c72d9c80043a8434db2c8a590 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 18:36:35 +0100 Subject: code beauty, reorganise --- src/elife_evas_smart.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 673bf8e..6687751 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -52,6 +52,8 @@ enum lifepattern_t { ELIFE_PAT_GLIDER = 5, ELIFE_PAT_LWSS = 6, }; +#define PATTERN_COUNT 7 + lifepattern_s lifepatterns[] = { [ELIFE_PAT_BEEHIVE] = {3, 4, "010101101010"}, [ELIFE_PAT_BOAT] = {3, 3, "010101011"}, @@ -61,7 +63,6 @@ lifepattern_s lifepatterns[] = { [ELIFE_PAT_GLIDER] = {3, 3, "010011101"}, [ELIFE_PAT_LWSS] = {5, 4, "10010000011000101111"}, }; -#define PATTERN_COUNT 7 enum lifemode { ELIFE_MODE_CONWAY, @@ -104,11 +105,14 @@ static void _elife_object_move(Evas_Object *o, Evas_Coord x, Evas_Coord y); static void _elife_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h); -/*static void _elife_object_show(Evas_Object *o); -static void _elife_object_hide(Evas_Object *o); -static void _elife_object_color_set(Evas_Object *o, int r, int g, int b, int a); -static void _elife_object_clip_set(Evas_Object *o, Evas_Object *clip); -static void _elife_object_clip_unset(Evas_Object *o); */ +/* Not implemented +static void _elife_object_show(Evas_Object *o); +static void _elife_object_hide(Evas_Object *o); +static void _elife_object_color_set(Evas_Object *o, int r, int g, int b, int a); +static void _elife_object_clip_set(Evas_Object *o, Evas_Object *clip); +static void _elife_object_clip_unset(Evas_Object *o); +*/ +static void *xmalloc(size_t size); static struct { Evas_Smart_Class klass; @@ -136,17 +140,6 @@ static struct { #define _G elife_evas_smart_g }; -void * -xmalloc(size_t size) -{ - void *x; - - x = malloc(size); - if (!x) - err(1, "Error: failed to allocate %d", size); - return x; -} - static struct grid * grid_new(Evas_Object *container, int w, int h, enum lifemode mode) { @@ -457,3 +450,14 @@ _elife_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) grid_redraw(grid, w, h); } +static void * +xmalloc(size_t size) +{ + void *x; + + x = malloc(size); + if (!x) + err(1, "Error: failed to allocate %d", size); + return x; +} + -- cgit v1.2.3-59-g8ed1b From 1be412760759e573e5f1351458136f3858023773 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 18:40:24 +0100 Subject: free memory on evas smart object deletion --- src/elife_evas_smart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 6687751..c8ecca1 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -180,7 +180,8 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) static void grid_del(struct grid *grid) { - /* program exits, OS will free */ + free(grid->cells); + free(grid); } static int -- cgit v1.2.3-59-g8ed1b From dbd0a4e5e416024bcfda9d96d15e7069e32e4a14 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 18:54:23 +0100 Subject: we cannot free grid->cells or we get crashes ... to be investigated --- src/elife_evas_smart.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index c8ecca1..046c5de 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -180,7 +180,9 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) static void grid_del(struct grid *grid) { - free(grid->cells); + //XXX if i delete grid->cells i get crashes + //XXX maybe evas is still using some objects after deletion ? + //free(grid->cells); free(grid); } -- cgit v1.2.3-59-g8ed1b From dc96ad7e96578efb2e726800acdf62643820bf4a Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 18:56:39 +0100 Subject: default size to 50x50 --- src/elife_evas_smart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 046c5de..e8eb7b4 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -29,8 +29,8 @@ #include "elife_evas_smart.h" -#define NCELL_X 40 -#define NCELL_Y 40 +#define NCELL_X 50 +#define NCELL_Y 50 #define INJECT_PROBA 30 #define DEBUG 0 -- cgit v1.2.3-59-g8ed1b From 796da3a5d849c65346f59472ffe8e1aa7c817b54 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 18:59:46 +0100 Subject: make a dicated define for INITCELL_PROBA and make it 1 living cell on 7 created cells --- src/elife_evas_smart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index e8eb7b4..a06bec6 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -32,6 +32,7 @@ #define NCELL_X 50 #define NCELL_Y 50 #define INJECT_PROBA 30 +#define INITCELL_PROBA 7 #define DEBUG 0 #define MIN(a,b) (((a)<(b))?(a):(b)) @@ -169,7 +170,7 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) cell->obj = o; cell->x = i; cell->y = j; - cell->age = !(rand() % 6); + cell->age = !(rand() % INITCELL_PROBA); evas_object_smart_member_add(o, container); } } -- cgit v1.2.3-59-g8ed1b From 82275f48f8a45b1719b2eda42845c2b0e8653c99 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 19:12:03 +0100 Subject: add install instructions --- README | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README b/README index c8550e2..2d56d4c 100644 --- a/README +++ b/README @@ -3,3 +3,13 @@ v1.0 Packaging and general structure from EEnvader.fractal by Boris Faure Many thanks to you Boris ! + + +Install +======= + +./autogen.sh +make +sudo make install + +elife will then appear in the "System" category of e17 wallpapers configuration panel. -- cgit v1.2.3-59-g8ed1b From 1a2c6e0d8c331cddaab361bdd01397a464d21dc9 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 19:14:50 +0100 Subject: add Dependencies section --- README | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README b/README index 2d56d4c..3e74c3e 100644 --- a/README +++ b/README @@ -4,6 +4,10 @@ v1.0 Packaging and general structure from EEnvader.fractal by Boris Faure Many thanks to you Boris ! +Dependencies +============ + +Enlightenment 0.16.999 (aka e17) Install ======= -- cgit v1.2.3-59-g8ed1b From 2644ace75026c97e8380d7544daeb125cf4aa4e9 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 19:18:46 +0100 Subject: bump version in README --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 3e74c3e..64c42f2 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ elife - Game of life / Living graphic -v1.0 +v1.1 Packaging and general structure from EEnvader.fractal by Boris Faure Many thanks to you Boris ! -- cgit v1.2.3-59-g8ed1b From d5a3db3e2d7f92fee9fc0101a4860fb1966bd62b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 19:32:01 +0100 Subject: remove useless comment --- src/elife_evas_smart.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index a06bec6..4d6cbfc 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -1,6 +1,5 @@ /* * elife - Game of life / Living graphic - * 2012 Laurent Ghigonis */ /* -- cgit v1.2.3-59-g8ed1b From 6fb08d81fbd1a050c256bf8e9cc0a2c436c0f41a Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 19:43:24 +0100 Subject: add "Elife slows down my e17" section --- README | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README b/README index 64c42f2..fa879a3 100644 --- a/README +++ b/README @@ -17,3 +17,17 @@ make sudo make install elife will then appear in the "System" category of e17 wallpapers configuration panel. + +Elife slows down my e17 ! +========================= + +elife is running in the same process as e17 therefore it can slow down the +whole window manager, depending on your machine CPU. + +To improve this, you can: + +* Use OpenGL rendering in e17 by using the Composite module, and set the engine +to OpenGL in Composite > Rendering pannel + +* Reduce the size of the elife grid by modifying the source code, in +src/elife_evas_smart.c at the definitions of NCELL_X and NCELL_Y -- cgit v1.2.3-59-g8ed1b From 979c7879a307d136c50863735267a18e4f179e10 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 20:12:12 +0100 Subject: add Future section --- README | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README b/README index fa879a3..1ce413a 100644 --- a/README +++ b/README @@ -31,3 +31,12 @@ to OpenGL in Composite > Rendering pannel * Reduce the size of the elife grid by modifying the source code, in src/elife_evas_smart.c at the definitions of NCELL_X and NCELL_Y + +Future +====== + +20:08 < loran> for the moment each cell is an evas_object. having the whole grid as one evas object and filling polygons manually (i'll take a look at seed + algorithm) might be faster, not sure +20:10 < loran> but if i can have opengl rendering for the background with composite module for example, then i will improve other parts of elife, like having cell + created on external events like new processes, packets blocked by firewall, ... +20:10 < loran> :p -- cgit v1.2.3-59-g8ed1b From a91d21613103eeadf5e5dc643b00d4f9df0c743c Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 20:13:58 +0100 Subject: mention the "elife" binary creation --- README | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README b/README index 1ce413a..87b6bf0 100644 --- a/README +++ b/README @@ -16,7 +16,8 @@ Install make sudo make install -elife will then appear in the "System" category of e17 wallpapers configuration panel. +"elife" will then appear in the "System" category of e17 wallpapers configuration panel. +A binary called "elife" is also created and install to run elife in standalone. Elife slows down my e17 ! ========================= -- cgit v1.2.3-59-g8ed1b From a97620627f3da9048005e9d6f9a041cc47970aaa Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 20:20:14 +0100 Subject: expand Future section and add TODO section --- README | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README b/README index 87b6bf0..572ebab 100644 --- a/README +++ b/README @@ -33,11 +33,24 @@ to OpenGL in Composite > Rendering pannel * Reduce the size of the elife grid by modifying the source code, in src/elife_evas_smart.c at the definitions of NCELL_X and NCELL_Y +TODO +==== + +* make install without sudo rights + Future ====== +freenode #e 20:08 < loran> for the moment each cell is an evas_object. having the whole grid as one evas object and filling polygons manually (i'll take a look at seed algorithm) might be faster, not sure 20:10 < loran> but if i can have opengl rendering for the background with composite module for example, then i will improve other parts of elife, like having cell created on external events like new processes, packets blocked by firewall, ... 20:10 < loran> :p +20:15 < drohan> it sounds interesting, but for future reference, you need a way to gain trust from the users, a background that uses cpu is not trusted, if you + change it as a widget or something else or try to comment all the code so the users can see what you are doing with it +20:16 < loran> haha good point :p +20:17 < drohan> and even then you will have a little problem with trust, change everything so you don't have to install it system wide, just local .e dir +20:17 < loran> i think you can run make install without system rights +20:17 < loran> without sudo + -- cgit v1.2.3-59-g8ed1b From e579983ceee017a4cc74a4bc2cfd48be92cd5fb6 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 20:23:01 +0100 Subject: typo --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 572ebab..8d146c7 100644 --- a/README +++ b/README @@ -17,7 +17,7 @@ make sudo make install "elife" will then appear in the "System" category of e17 wallpapers configuration panel. -A binary called "elife" is also created and install to run elife in standalone. +A binary called "elife" is also created and installed to run elife in standalone. Elife slows down my e17 ! ========================= -- cgit v1.2.3-59-g8ed1b From ce6d45550a657ef83513e24e94193998e2b0ca0a Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 20:27:33 +0100 Subject: add "Code organisation" section --- README | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README b/README index 8d146c7..41682c4 100644 --- a/README +++ b/README @@ -54,3 +54,8 @@ freenode #e 20:17 < loran> i think you can run make install without system rights 20:17 < loran> without sudo +Code organisation +================= + +The core code is in src/elife_evas_smart.c +All the other files are here to build standalone binary and edje file. -- cgit v1.2.3-59-g8ed1b From 6c8427f75d82533da454808ce04f0c08a8a37aad Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 20:40:49 +0100 Subject: add releases --- NEWS | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 8b13789..e4a4e1f 100644 --- a/NEWS +++ b/NEWS @@ -1 +1,4 @@ - +git log --reverse --tags --simplify-by-decoration --pretty="format:%ai %d" +2012-10-14 16:35:56 +0200 +2012-11-04 18:59:46 +0100 (v1.0) +2012-11-04 19:14:50 +0100 (v1.1) -- cgit v1.2.3-59-g8ed1b From 69112aeafc73104cbb71fd4968524661ef75174b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 20:53:22 +0100 Subject: remove TODO from source, it's in README now --- src/elife_evas_smart.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 4d6cbfc..98b59fb 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -18,11 +18,6 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* - * TODO - * - */ - #include #include -- cgit v1.2.3-59-g8ed1b From 5b683c0c268dce0cb7e844ffc7436d080ce794de Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 20:54:58 +0100 Subject: small code explanation --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index 41682c4..dd9dce3 100644 --- a/README +++ b/README @@ -59,3 +59,6 @@ Code organisation The core code is in src/elife_evas_smart.c All the other files are here to build standalone binary and edje file. + +src/elife_evas_smart.c + At each life cycle, grid_evolution() gets called -- cgit v1.2.3-59-g8ed1b From 7e619858a1453a36330dce657dbdcf97d83453e1 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 4 Nov 2012 21:07:09 +0100 Subject: implement death for CONWAY_GROW mode --- src/elife_evas_smart.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 98b59fb..3bc8f45 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -27,6 +27,7 @@ #define NCELL_Y 50 #define INJECT_PROBA 30 #define INITCELL_PROBA 7 +#define CONWAY_GROW_DIE 600 #define DEBUG 0 #define MIN(a,b) (((a)<(b))?(a):(b)) @@ -210,7 +211,10 @@ grid_evolution(struct grid *grid) if (cell->age == 0 && neighbours == 3) cell->newage = 1; else if (cell->age > 0 && (neighbours == 2 || neighbours == 3)) - cell->newage = cell->age + 1; + if (cell->age > CONWAY_GROW_DIE) + cell->newage = 0; + else + cell->newage = cell->age + 1; else cell->newage = 0; break; -- cgit v1.2.3-59-g8ed1b From cce2d2abaf08868afeef5be89bce0c7a7442d713 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 00:39:28 +0100 Subject: nicer cell colors --- src/elife_evas_smart.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 3bc8f45..88aed3f 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -333,9 +333,15 @@ cell_redraw(struct cell *c) { int r, g, b, a; - r = (c->age > 0) ? 128 : 0; - g = (c->age > 0) ? (33 + c->age * 7) : 0; - b = (c->age > 0) ? 0 : 0; + if (c->age < 100) { + r = (c->age > 0) ? 128 : 0; + g = (c->age > 0) ? (33 + c->age * 7) : 0; + b = 0; + } else { + r = 128 - c->age; + g = 255 - c->age; + b = (c->age - 100) * 2; + } a = 255; evas_object_color_set(c->obj, r, g, b, a); } -- cgit v1.2.3-59-g8ed1b From f116e2329f6ca0ee302b8b2bfe55ceb215e13f91 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 01:08:23 +0100 Subject: optimisation ideas --- README | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README b/README index dd9dce3..9cef53b 100644 --- a/README +++ b/README @@ -54,6 +54,9 @@ freenode #e 20:17 < loran> i think you can run make install without system rights 20:17 < loran> without sudo +Optimisation ideas: +* one evas_object_rectangle, manualy write memory inside it + Code organisation ================= -- cgit v1.2.3-59-g8ed1b From c0191cb82d2858ffe0dec7b2dc1f09c5ca09159f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 02:02:07 +0100 Subject: work in progress, i broke everything --- src/elife_evas_smart.c | 61 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 88aed3f..94c5090 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -67,14 +67,15 @@ enum lifemode { }; struct cell { - Evas_Object *obj; int age, newage; int x, y; + int r, g, b; }; struct grid { struct cell *cells; - Evas_Object *obj; + Evas_Object *rectangle; + int *mem; int w, h; int age; enum lifemode mode; @@ -88,7 +89,7 @@ static void grid_inject_pattern(struct grid *grid); static int grid_redraw(struct grid *grid, int w, int h); static int cell_neighbours_count(struct cell *cell, struct grid *grid); static int cell_redraw(struct cell *c); -static void cell_mouse_down(void *data, Evas *evas, Evas_Object *child, +static void grid_mouse_down(void *data, Evas *evas, Evas_Object *child, void *event_info); Evas_Object *elife_smart_new(Evas *e); @@ -143,9 +144,24 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) struct cell *cell; Evas_Object *o; int i, j; + int *mem; g = xmalloc(sizeof(struct grid)); g->obj = container; + o = evas_object_image_filled_add(evas_object_evas_get(container)); + if (!o) + err(1, "Cannot create image for grid"); + evas_object_image_alpha_set(o, EINA_FALSE); + evas_object_image_fill_set(o, 0, 0, w, h); + evas_object_image_smooth_scale_set(o, EINA_FALSE); + evas_object_image_size_set (o, w, h); + evas_object_data_set(o, "grid", g); + evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, + grid_mouse_down, grid); + g->image = o + mem = xmalloc(w * h * sizeof(int)); + evas_object_image_data_set(g->image, (void *) mem); + g->mem = mem; g->w = w; g->h = w; g->age = 0; @@ -154,19 +170,9 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) for (j=0; jobj = o; cell->x = i; cell->y = j; cell->age = !(rand() % INITCELL_PROBA); - evas_object_smart_member_add(o, container); } } @@ -176,9 +182,8 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) static void grid_del(struct grid *grid) { - //XXX if i delete grid->cells i get crashes - //XXX maybe evas is still using some objects after deletion ? //free(grid->cells); + //free(grid->mem); free(grid); } @@ -186,14 +191,9 @@ static int grid_evolution(struct grid *grid) { struct cell *cell; - int container_w, container_h, cell_w, cell_h; int i, j; int neighbours; - evas_object_geometry_get(grid->obj, &container_w, &container_h, NULL, NULL); - cell_w = container_w / grid->w; - cell_h = container_h / grid->h; - for (j=0; jh; j++) { for (i=0; iw; i++) { cell = CELL_GET(grid, i, j); @@ -291,14 +291,11 @@ grid_redraw(struct grid *grid, int w, int h) if (DEBUG) printf("redraw: container %d %d cell %d %d\n", w, h, cell_w, cell_h); + // XXX resize rectangle, realloc mem, redraw all cells for (j=0; jh; j++) { for (i=0; iw; i++) { cell = CELL_GET(grid, i, j); - o = cell->obj; - evas_object_resize(o, cell_w, cell_h); - evas_object_move(o, i*cell_w, j*cell_h); - cell_redraw(cell); - evas_object_show(o); + // XXX } } } @@ -343,22 +340,24 @@ cell_redraw(struct cell *c) b = (c->age - 100) * 2; } a = 255; - evas_object_color_set(c->obj, r, g, b, a); + if (r == c->r && g == c->g && b == c->b) + return; + + // XXX fill rectlange region in grid->mem } static void -cell_mouse_down(void *data, +grid_mouse_down(void *data, Evas *evas, Evas_Object *child, void *event_info) { Evas_Coord x, y, w, h; Evas_Event_Mouse_Up *evt = event_info; - struct cell *cell; + struct grid *grid; - cell = data; - cell->age++; - cell_redraw(cell); + grid = data; + // XXX } Evas_Object * -- cgit v1.2.3-59-g8ed1b From 02cc8018c831b9de49511fe9de6cd45188826851 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 02:04:43 +0100 Subject: blink when you will die --- src/elife_evas_smart.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 88aed3f..7afb588 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -337,10 +337,14 @@ cell_redraw(struct cell *c) r = (c->age > 0) ? 128 : 0; g = (c->age > 0) ? (33 + c->age * 7) : 0; b = 0; - } else { + } else if (c->age < CONWAY_GROW_DIE - 50) { r = 128 - c->age; g = 255 - c->age; b = (c->age - 100) * 2; + } else { + r = 255; + g = (c->age % 2) * 255; + b = 255; } a = 255; evas_object_color_set(c->obj, r, g, b, a); -- cgit v1.2.3-59-g8ed1b From eec092dcb2d37c53d0e7200dc48010a348af8b02 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 02:45:24 +0100 Subject: code for image writing is here now --- src/elife_evas_smart.c | 55 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 94c5090..a1f1cd4 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -73,10 +73,13 @@ struct cell { }; struct grid { + Evas_Object *container; struct cell *cells; - Evas_Object *rectangle; + Evas_Object *image; int *mem; int w, h; + int pix_w, pix_h; + int cell_pix_w, cell_pix_h; int age; enum lifemode mode; }; @@ -88,7 +91,7 @@ static int grid_evolution(struct grid *grid); static void grid_inject_pattern(struct grid *grid); static int grid_redraw(struct grid *grid, int w, int h); static int cell_neighbours_count(struct cell *cell, struct grid *grid); -static int cell_redraw(struct cell *c); +static void cell_redraw(struct cell *c, struct grid *g); static void grid_mouse_down(void *data, Evas *evas, Evas_Object *child, void *event_info); @@ -147,19 +150,18 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) int *mem; g = xmalloc(sizeof(struct grid)); - g->obj = container; + g->container = container; o = evas_object_image_filled_add(evas_object_evas_get(container)); if (!o) err(1, "Cannot create image for grid"); evas_object_image_alpha_set(o, EINA_FALSE); - evas_object_image_fill_set(o, 0, 0, w, h); evas_object_image_smooth_scale_set(o, EINA_FALSE); - evas_object_image_size_set (o, w, h); evas_object_data_set(o, "grid", g); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, - grid_mouse_down, grid); - g->image = o - mem = xmalloc(w * h * sizeof(int)); + grid_mouse_down, g); + evas_object_show(o); + g->image = o; + mem = xmalloc(1); evas_object_image_data_set(g->image, (void *) mem); g->mem = mem; g->w = w; @@ -244,7 +246,7 @@ grid_evolution(struct grid *grid) for (i=0; iw; i++) { cell = CELL_GET(grid, i, j); cell->age = cell->newage; - cell_redraw(cell); + cell_redraw(cell, grid); } } @@ -282,20 +284,25 @@ static int grid_redraw(struct grid *grid, int w, int h) { struct cell *cell; - int cell_w, cell_h; int i,j; Evas_Object *o; - cell_w = w / grid->w; - cell_h = h / grid->h; + grid->pix_w = w; + grid->pix_h = h; + grid->cell_pix_w = w / grid->w; + grid->cell_pix_w = h / grid->h; if (DEBUG) - printf("redraw: container %d %d cell %d %d\n", w, h, cell_w, cell_h); + printf("redraw: container %d %d cell %d %d\n", w, h, grid->cell_pix_w, grid->cell_pix_h); - // XXX resize rectangle, realloc mem, redraw all cells + evas_object_image_fill_set(grid->image, 0, 0, w, h); + evas_object_image_size_set (grid->image, w, h); + grid->mem = realloc(grid->mem, w * h * sizeof(int)); + if (!grid->mem) + err(1, "could not realloc grid->mem"); for (j=0; jh; j++) { for (i=0; iw; i++) { cell = CELL_GET(grid, i, j); - // XXX + cell_redraw(cell, grid); } } } @@ -325,10 +332,13 @@ cell_neighbours_count(struct cell *cell, struct grid *grid) return count; } -static int -cell_redraw(struct cell *c) +static void +cell_redraw(struct cell *c, struct grid *grid) { int r, g, b, a; + int x, y, w, h; + int i, j; + int color; if (c->age < 100) { r = (c->age > 0) ? 128 : 0; @@ -343,7 +353,16 @@ cell_redraw(struct cell *c) if (r == c->r && g == c->g && b == c->b) return; - // XXX fill rectlange region in grid->mem + x = c->x; + y = c->y; + w = grid->cell_pix_w; + h = grid->cell_pix_h; + for (j=y; jmem[j*grid->pix_w + i] = color; + } + } } static void -- cgit v1.2.3-59-g8ed1b From bb8d34e57e09bf693d443a4be0e5324a906ddc78 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 02:46:03 +0100 Subject: activate debug and reduce grid size for debug --- src/elife_evas_smart.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index a1f1cd4..3064b4d 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -23,12 +23,12 @@ #include "elife_evas_smart.h" -#define NCELL_X 50 -#define NCELL_Y 50 +#define NCELL_X 10 +#define NCELL_Y 10 #define INJECT_PROBA 30 #define INITCELL_PROBA 7 #define CONWAY_GROW_DIE 600 -#define DEBUG 0 +#define DEBUG 1 #define MIN(a,b) (((a)<(b))?(a):(b)) #define CELL_GET(grid, x, y) &(grid->cells[(y*grid->w) + x]) -- cgit v1.2.3-59-g8ed1b From f2fd04bd5b197e4717c3502813b956fe6bbbcdfc Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 03:29:50 +0100 Subject: it works it works ! much performance improvements compaired to the multi evas_object implementation increase grid size to 200x200 --- src/elife_evas_smart.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 3064b4d..563c501 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -23,12 +23,12 @@ #include "elife_evas_smart.h" -#define NCELL_X 10 -#define NCELL_Y 10 +#define NCELL_X 200 +#define NCELL_Y 200 #define INJECT_PROBA 30 #define INITCELL_PROBA 7 #define CONWAY_GROW_DIE 600 -#define DEBUG 1 +#define DEBUG 0 #define MIN(a,b) (((a)<(b))?(a):(b)) #define CELL_GET(grid, x, y) &(grid->cells[(y*grid->w) + x]) @@ -147,7 +147,6 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) struct cell *cell; Evas_Object *o; int i, j; - int *mem; g = xmalloc(sizeof(struct grid)); g->container = container; @@ -159,13 +158,12 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) evas_object_data_set(o, "grid", g); evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN, grid_mouse_down, g); + evas_object_smart_member_add(o, container); evas_object_show(o); g->image = o; - mem = xmalloc(1); - evas_object_image_data_set(g->image, (void *) mem); - g->mem = mem; + g->mem = NULL; g->w = w; - g->h = w; + g->h = h; g->age = 0; g->mode = mode; g->cells = xmalloc(sizeof(struct cell) * w * h); @@ -174,6 +172,9 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) cell = CELL_GET(g, i, j); cell->x = i; cell->y = j; + cell->r = 0; + cell->g = 0; + cell->b = 0; cell->age = !(rand() % INITCELL_PROBA); } } @@ -249,6 +250,7 @@ grid_evolution(struct grid *grid) cell_redraw(cell, grid); } } + evas_object_image_pixels_dirty_set(grid->image, EINA_TRUE); grid->age++; } @@ -290,15 +292,19 @@ grid_redraw(struct grid *grid, int w, int h) grid->pix_w = w; grid->pix_h = h; grid->cell_pix_w = w / grid->w; - grid->cell_pix_w = h / grid->h; + grid->cell_pix_h = h / grid->h; if (DEBUG) printf("redraw: container %d %d cell %d %d\n", w, h, grid->cell_pix_w, grid->cell_pix_h); evas_object_image_fill_set(grid->image, 0, 0, w, h); evas_object_image_size_set (grid->image, w, h); - grid->mem = realloc(grid->mem, w * h * sizeof(int)); + evas_object_resize(grid->image, w, h); + if (grid->mem) + free(grid->mem); + grid->mem = calloc(w * h, sizeof(int)); if (!grid->mem) - err(1, "could not realloc grid->mem"); + err(1, "could not calloc grid->mem"); + evas_object_image_data_set(grid->image, (void *) grid->mem); for (j=0; jh; j++) { for (i=0; iw; i++) { cell = CELL_GET(grid, i, j); @@ -352,9 +358,12 @@ cell_redraw(struct cell *c, struct grid *grid) a = 255; if (r == c->r && g == c->g && b == c->b) return; + c->r = r; + c->g = g; + c->b = b; - x = c->x; - y = c->y; + x = c->x * grid->cell_pix_w; + y = c->y * grid->cell_pix_h; w = grid->cell_pix_w; h = grid->cell_pix_h; for (j=y; j Date: Mon, 5 Nov 2012 03:30:45 +0100 Subject: imcrease speed ! --- data/elife.edc | 2 +- src/elife.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/elife.edc b/data/elife.edc index 828704c..b58ef9c 100644 --- a/data/elife.edc +++ b/data/elife.edc @@ -9,7 +9,7 @@ collections { script { public clock_cb(unused) { emit("elife:refresh", "☃"); - timer(1, "clock_cb", 1); + timer(0.3, "clock_cb", 1); } } diff --git a/src/elife.c b/src/elife.c index 46f799b..7ebc157 100644 --- a/src/elife.c +++ b/src/elife.c @@ -93,7 +93,7 @@ main(void) evas_object_resize(_G.elife, _G.w, _G.h); evas_object_show(_G.elife); - ecore_timer_add(1, timer_cb, _G.elife); + ecore_timer_add(0.1, timer_cb, _G.elife); ecore_evas_callback_resize_set(_G.ee, &resize_cb); -- cgit v1.2.3-59-g8ed1b From 73bc4d2e503c120cbc2a454496e7c64fbd76d1b9 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 03:34:11 +0100 Subject: more reasonable speed and size for a wallpaper --- data/elife.edc | 2 +- src/elife_evas_smart.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/data/elife.edc b/data/elife.edc index b58ef9c..d8f1a65 100644 --- a/data/elife.edc +++ b/data/elife.edc @@ -9,7 +9,7 @@ collections { script { public clock_cb(unused) { emit("elife:refresh", "☃"); - timer(0.3, "clock_cb", 1); + timer(0.8, "clock_cb", 1); } } diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 563c501..086b1a2 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -23,8 +23,8 @@ #include "elife_evas_smart.h" -#define NCELL_X 200 -#define NCELL_Y 200 +#define NCELL_X 100 +#define NCELL_Y 100 #define INJECT_PROBA 30 #define INITCELL_PROBA 7 #define CONWAY_GROW_DIE 600 -- cgit v1.2.3-59-g8ed1b From d768de106758ecbad247e88c7c97775e2f6865a8 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 04:06:26 +0100 Subject: TODO++ --- README | 1 + 1 file changed, 1 insertion(+) diff --git a/README b/README index 9cef53b..e1b5d69 100644 --- a/README +++ b/README @@ -37,6 +37,7 @@ TODO ==== * make install without sudo rights +* make a gadget Future ====== -- cgit v1.2.3-59-g8ed1b From c7fcc07f9f9602058447af7769e1cdfd185493a7 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 04:06:39 +0100 Subject: fix object size so it does fit the container size exactly. also call grid_inject_pattern() on mouse down. --- src/elife_evas_smart.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 086b1a2..09445e5 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -289,16 +289,17 @@ grid_redraw(struct grid *grid, int w, int h) int i,j; Evas_Object *o; - grid->pix_w = w; - grid->pix_h = h; grid->cell_pix_w = w / grid->w; grid->cell_pix_h = h / grid->h; + grid->pix_w = (w / grid->w) * grid->w; + grid->pix_h = (h / grid->h) * grid->h; if (DEBUG) printf("redraw: container %d %d cell %d %d\n", w, h, grid->cell_pix_w, grid->cell_pix_h); - evas_object_image_fill_set(grid->image, 0, 0, w, h); - evas_object_image_size_set (grid->image, w, h); + evas_object_image_fill_set(grid->image, 0, 0, grid->pix_w, grid->pix_h); + evas_object_image_size_set (grid->image, grid->pix_w, grid->pix_h); evas_object_resize(grid->image, w, h); + /* XXX could be optimized to avoid flickering on resize */ if (grid->mem) free(grid->mem); grid->mem = calloc(w * h, sizeof(int)); @@ -385,7 +386,7 @@ grid_mouse_down(void *data, struct grid *grid; grid = data; - // XXX + grid_inject_pattern(grid); } Evas_Object * -- cgit v1.2.3-59-g8ed1b From 8e8b436e7d380eae103c37dfe1ecde97e5d28638 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 04:09:01 +0100 Subject: increase inject proba --- src/elife_evas_smart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 243973b..cca8ef5 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -25,7 +25,7 @@ #define NCELL_X 100 #define NCELL_Y 100 -#define INJECT_PROBA 30 +#define INJECT_PROBA 40 #define INITCELL_PROBA 7 #define CONWAY_GROW_DIE 600 #define DEBUG 0 -- cgit v1.2.3-59-g8ed1b From bcb4971250124f27db9acbd6d0a22f9f3fb8e6e3 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 04:12:28 +0100 Subject: move "Future" to "Ideas" --- README | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README b/README index e1b5d69..8e3c823 100644 --- a/README +++ b/README @@ -39,8 +39,17 @@ TODO * make install without sudo rights * make a gadget -Future -====== +Code organisation +================= + +The core code is in src/elife_evas_smart.c +All the other files are here to build standalone binary and edje file. + +src/elife_evas_smart.c + At each life cycle, grid_evolution() gets called + +Ideas +===== freenode #e 20:08 < loran> for the moment each cell is an evas_object. having the whole grid as one evas object and filling polygons manually (i'll take a look at seed @@ -56,13 +65,5 @@ freenode #e 20:17 < loran> without sudo Optimisation ideas: -* one evas_object_rectangle, manualy write memory inside it +* one evas_object_rectangle, manualy write memory inside it (DONE) -Code organisation -================= - -The core code is in src/elife_evas_smart.c -All the other files are here to build standalone binary and edje file. - -src/elife_evas_smart.c - At each life cycle, grid_evolution() gets called -- cgit v1.2.3-59-g8ed1b From 642140c73704beaeed79e815d8c27b5919f11db0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 04:12:52 +0100 Subject: bump version --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 8e3c823..be7428e 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ elife - Game of life / Living graphic -v1.1 +v1.2 Packaging and general structure from EEnvader.fractal by Boris Faure Many thanks to you Boris ! -- cgit v1.2.3-59-g8ed1b From 878b0276f70134dc1559e347eb75dc43e84143b5 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 04:16:00 +0100 Subject: bump NEWS --- NEWS | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index e4a4e1f..5c5261f 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,6 @@ -git log --reverse --tags --simplify-by-decoration --pretty="format:%ai %d" +bal$ git log --reverse --tags --simplify-by-decoration --pretty="format:%ai %d" 2012-10-14 16:35:56 +0200 2012-11-04 18:59:46 +0100 (v1.0) 2012-11-04 19:14:50 +0100 (v1.1) +2012-11-05 04:09:01 +0100 (origin/master, origin/manual_draw, manual_draw) +2012-11-05 04:12:52 +0100 (HEAD, v1.2, master) -- cgit v1.2.3-59-g8ed1b From 137b99160597e9e7141b7c7b3f891671734fc159 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 04:26:12 +0100 Subject: redraw cell in grid_pattern_inject() fixes pattern injection on mouse down --- src/elife_evas_smart.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index cca8ef5..8d2dccd 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -278,6 +278,8 @@ grid_inject_pattern(struct grid *grid) continue; cell = CELL_GET(grid, cx, cy); cell->newage = (pat->pat[pat->w*j + i] - '0') * 27; + cell->age = cell->newage; + cell_redraw(cell, grid); } } } -- cgit v1.2.3-59-g8ed1b From 2ace903b27b675a8468904fdd40250a5277bec78 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 04:33:18 +0100 Subject: add comment on free() --- src/elife_evas_smart.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 8d2dccd..22208de 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -185,6 +185,7 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) static void grid_del(struct grid *grid) { + // XXX investigate evas usage of objects after free //free(grid->cells); //free(grid->mem); free(grid); -- cgit v1.2.3-59-g8ed1b From 09d14a76fc78376006f744e5c9f860ae353047fb Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 5 Nov 2012 04:36:29 +0100 Subject: fix window title --- src/elife.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elife.c b/src/elife.c index 7ebc157..8b97cb8 100644 --- a/src/elife.c +++ b/src/elife.c @@ -74,7 +74,7 @@ main(void) 0, /* Ecore_X_Window parent */ 0, 0, _G.w, _G.h); - ecore_evas_title_set(_G.ee, "EEnavders.fractal"); + ecore_evas_title_set(_G.ee, "elife"); ecore_evas_borderless_set(_G.ee, 0); ecore_evas_show(_G.ee); _G.evas = ecore_evas_get(_G.ee); -- cgit v1.2.3-59-g8ed1b From 8b525368aad5528848ad5e1057f1e0836691843d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 30 Nov 2012 09:54:22 +0100 Subject: fix evas object delete calls, so we can now free the grid content without crash :) --- src/elife_evas_smart.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 22208de..6ef820c 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -185,9 +185,8 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) static void grid_del(struct grid *grid) { - // XXX investigate evas usage of objects after free - //free(grid->cells); - //free(grid->mem); + free(grid->cells); + free(grid->mem); free(grid); } @@ -456,7 +455,7 @@ _elife_object_del(Evas_Object *o) evas_object_smart_member_del(child); evas_object_del(child); } - grid = evas_object_data_del(child, "grid"); + grid = evas_object_data_del(o, "grid"); grid_del(grid); } -- cgit v1.2.3-59-g8ed1b From 3d5530db1fa2b90ba01e27bffab3df97ca341eb3 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 30 Nov 2012 09:55:24 +0100 Subject: cell redraw when injecting pattern is not needed --- src/elife_evas_smart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index 6ef820c..ff744f8 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -279,7 +279,7 @@ grid_inject_pattern(struct grid *grid) cell = CELL_GET(grid, cx, cy); cell->newage = (pat->pat[pat->w*j + i] - '0') * 27; cell->age = cell->newage; - cell_redraw(cell, grid); + // cell_redraw(cell, grid); } } } -- cgit v1.2.3-59-g8ed1b From 75cda851a5cebbb177bc9d2e97fc3f20645c2129 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 30 Nov 2012 09:55:47 +0100 Subject: add conditionnal glouglou support :) --- README | 10 ++++++++++ configure.ac | 9 +++++++++ src/Makefile.am | 12 ++++++++++-- src/elife_evas_smart.c | 38 ++++++++++++++++++++++++++++++++++++-- 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/README b/README index be7428e..1906131 100644 --- a/README +++ b/README @@ -19,6 +19,16 @@ sudo make install "elife" will then appear in the "System" category of e17 wallpapers configuration panel. A binary called "elife" is also created and installed to run elife in standalone. +Glouglou support +================ + +To enable glouglou support, pass --enable-glouglou to automake scripts : +./autogen.sh --enable-glouglou +OR +./configure --enable-glouglou + +You will need libglouglou and glougloud + Elife slows down my e17 ! ========================= diff --git a/configure.ac b/configure.ac index 7c19b4b..60d1703 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,15 @@ AC_ARG_ENABLE(homedir-install, ) AC_SUBST(datadir_edj) +AC_ARG_ENABLE(glouglou, +[ --enable-glouglou Enable glouglou support], +[case "${enableval}" in + yes) glouglou=true ;; + no) glouglou=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-glouglou) ;; +esac],[glouglou=false]) +AM_CONDITIONAL(HAVE_GLOUGLOU, test x$glouglou = xtrue) + AC_OUTPUT([ Makefile data/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 7f6bd71..f8135a0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,18 +12,26 @@ module_la_SOURCES = \ elife_edje_external.c module_la_LIBADD = @ELIFE_LIBS@ -module_la_LDFLAGS = -module -avoid-version module_la_DEPENDENCIES = $(top_builddir)/config.h bin_PROGRAMS = elife - elife_SOURCES = \ elife_evas_smart.c \ elife.c elife_CPPFLAGS = \ @ELIFE_CFLAGS@ + +if HAVE_GLOUGLOU +module_la_LDFLAGS = -module -avoid-version -lglouglou -levent +module_la_CFLAGS = -DHAVE_GLOUGLOU +elife_LDADD = \ + @ELIFE_LIBS@ -lglouglou -levent +elife_CFLAGS = -DHAVE_GLOUGLOU +else +module_la_LDFLAGS = -module -avoid-version elife_LDADD = \ @ELIFE_LIBS@ +endif clean-local: rm -rf *~ diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index ff744f8..bde26ff 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -23,6 +23,10 @@ #include "elife_evas_smart.h" +#ifdef HAVE_GLOUGLOU +#include +#endif + #define NCELL_X 100 #define NCELL_Y 100 #define INJECT_PROBA 40 @@ -82,6 +86,10 @@ struct grid { int cell_pix_w, cell_pix_h; int age; enum lifemode mode; +#ifdef HAVE_GLOUGLOU + struct gg_client *ggcli; + struct event_base *ev_base; +#endif }; static struct grid *grid_new(Evas_Object *container, @@ -112,7 +120,7 @@ static void _elife_object_color_set(Evas_Object *o, int r, int g, int b, int static void _elife_object_clip_set(Evas_Object *o, Evas_Object *clip); static void _elife_object_clip_unset(Evas_Object *o); */ -static void *xmalloc(size_t size); +void *xmalloc(size_t size); static struct { Evas_Smart_Class klass; @@ -140,6 +148,19 @@ static struct { #define _G elife_evas_smart_g }; +#ifdef HAVE_GLOUGLOU +int +gg_packet(struct gg_client *cli, struct gg_packet *pkt) +{ + struct grid *grid; + + grid = cli->usrdata; + grid_inject_pattern(grid); + + return 0; +} +#endif + static struct grid * grid_new(Evas_Object *container, int w, int h, enum lifemode mode) { @@ -179,12 +200,21 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) } } +#ifdef HAVE_GLOUGLOU + g->ev_base = event_base_new(); + g->ggcli = gg_client_connect(g->ev_base, "127.0.0.1", GLOUGLOU_ANALY_DEFAULT_PORT, + NULL, gg_packet, g); +#endif + return g; } static void grid_del(struct grid *grid) { +#ifdef HAVE_GLOUGLOU + gg_client_disconnect(grid->ggcli); +#endif free(grid->cells); free(grid->mem); free(grid); @@ -240,8 +270,12 @@ grid_evolution(struct grid *grid) } } +#ifdef HAVE_GLOUGLOU + event_base_loop(grid->ev_base, EVLOOP_NONBLOCK); +#else if (rand() % INJECT_PROBA == 0) grid_inject_pattern(grid); +#endif for (j=0; jh; j++) { for (i=0; iw; i++) { @@ -492,7 +526,7 @@ _elife_object_resize(Evas_Object *o, Evas_Coord w, Evas_Coord h) grid_redraw(grid, w, h); } -static void * +void * xmalloc(size_t size) { void *x; -- cgit v1.2.3-59-g8ed1b From 0468049ba9c7701fcc4f0999fda4511ba2eaa8da Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 30 Nov 2012 15:42:30 +0100 Subject: display different fixed colors based on glouglou event. for now only handle process events --- src/elife_evas_smart.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index bde26ff..b732294 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -72,6 +72,7 @@ enum lifemode { struct cell { int age, newage; + u_int32_t forced_color; int x, y; int r, g, b; }; @@ -96,7 +97,7 @@ static struct grid *grid_new(Evas_Object *container, int w, int h, enum lifemode mode); static void grid_del(struct grid *grid); static int grid_evolution(struct grid *grid); -static void grid_inject_pattern(struct grid *grid); +static void grid_inject_pattern(struct grid *grid, u_int32_t color); static int grid_redraw(struct grid *grid, int w, int h); static int cell_neighbours_count(struct cell *cell, struct grid *grid); static void cell_redraw(struct cell *c, struct grid *g); @@ -153,9 +154,16 @@ int gg_packet(struct gg_client *cli, struct gg_packet *pkt) { struct grid *grid; + u_int32_t color; grid = cli->usrdata; - grid_inject_pattern(grid); + switch(pkt->type) { + case PACKET_FORK: color=0xff0000; break; + case PACKET_EXEC: color=0x00ff00; break; + case PACKET_EXIT: color=0x0000ff; break; + default: color=0x0f00f0; break; + } + grid_inject_pattern(grid, color); return 0; } @@ -196,6 +204,7 @@ grid_new(Evas_Object *container, int w, int h, enum lifemode mode) cell->r = 0; cell->g = 0; cell->b = 0; + cell->forced_color = 0x000000; cell->age = !(rand() % INITCELL_PROBA); } } @@ -264,6 +273,8 @@ grid_evolution(struct grid *grid) cell->newage = 0; break; } + if (cell->newage == 0 && cell->forced_color) + cell->forced_color = 0; if (DEBUG) printf("evolution: %d %d n %d age %d newage %d\n", i, j, neighbours, cell->age, cell->newage); @@ -274,7 +285,7 @@ grid_evolution(struct grid *grid) event_base_loop(grid->ev_base, EVLOOP_NONBLOCK); #else if (rand() % INJECT_PROBA == 0) - grid_inject_pattern(grid); + grid_inject_pattern(grid, 0); #endif for (j=0; jh; j++) { @@ -290,7 +301,7 @@ grid_evolution(struct grid *grid) } static void -grid_inject_pattern(struct grid *grid) +grid_inject_pattern(struct grid *grid, u_int32_t color) { struct cell *cell; enum lifepattern_t npat; @@ -312,6 +323,7 @@ grid_inject_pattern(struct grid *grid) continue; cell = CELL_GET(grid, cx, cy); cell->newage = (pat->pat[pat->w*j + i] - '0') * 27; + cell->forced_color = color; cell->age = cell->newage; // cell_redraw(cell, grid); } @@ -378,12 +390,16 @@ cell_neighbours_count(struct cell *cell, struct grid *grid) static void cell_redraw(struct cell *c, struct grid *grid) { - int r, g, b, a; + u_int8_t r, g, b, a; int x, y, w, h; int i, j; int color; - if (c->age < 100) { + if (c->forced_color && c->age > 0) { + r = (c->forced_color & 0xff0000) >> 16; + g = (c->forced_color & 0xff00) >> 8; + b = (c->forced_color & 0xff); + } else if (c->age < 100) { r = (c->age > 0) ? 128 : 0; g = (c->age > 0) ? (33 + c->age * 7) : 0; b = 0; @@ -426,7 +442,7 @@ grid_mouse_down(void *data, struct grid *grid; grid = data; - grid_inject_pattern(grid); + grid_inject_pattern(grid, 0); } Evas_Object * -- cgit v1.2.3-59-g8ed1b From 4da9606c971a5c53eba4238805b2fbb4c01dfdbf Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 30 Nov 2012 16:06:26 +0100 Subject: when injecting pattern, do not erase living cells --- src/elife_evas_smart.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index b732294..f14e534 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -308,6 +308,7 @@ grid_inject_pattern(struct grid *grid, u_int32_t color) lifepattern_s *pat; int x, y, cx, cy; int i, j; + int age; npat = rand() % PATTERN_COUNT; if (DEBUG) @@ -322,7 +323,9 @@ grid_inject_pattern(struct grid *grid, u_int32_t color) if (cx >= grid->w || cy >= grid->h) continue; cell = CELL_GET(grid, cx, cy); - cell->newage = (pat->pat[pat->w*j + i] - '0') * 27; + age = (pat->pat[pat->w*j + i] - '0') * 27; + if (age != 0) + cell->newage = age; cell->forced_color = color; cell->age = cell->newage; // cell_redraw(cell, grid); -- cgit v1.2.3-59-g8ed1b From fe0df0cd3b0af03ac248d406b47c34ec7fca2ec2 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 30 Nov 2012 16:24:49 +0100 Subject: reduce the timer to update background every half second --- data/elife.edc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/elife.edc b/data/elife.edc index d8f1a65..69df75c 100644 --- a/data/elife.edc +++ b/data/elife.edc @@ -9,7 +9,7 @@ collections { script { public clock_cb(unused) { emit("elife:refresh", "☃"); - timer(0.8, "clock_cb", 1); + timer(0.5, "clock_cb", 1); } } -- cgit v1.2.3-59-g8ed1b From 7128fdd567c806b249fd715ba94976db634cee4c Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 03:37:18 +0100 Subject: initial import. only compiles, not functionnal --- Egraph.h | 48 ++++++++++++++++ Makefile | 28 ++++++++++ README.txt | 16 ++++++ egraph.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 276 insertions(+) create mode 100644 Egraph.h create mode 100644 Makefile create mode 100644 README.txt create mode 100644 egraph.c diff --git a/Egraph.h b/Egraph.h new file mode 100644 index 0000000..502b64d --- /dev/null +++ b/Egraph.h @@ -0,0 +1,48 @@ +#include +#include +#include + +#define EGRAPH_VERTICES_MAX 16384 /* cannot be more that u_int32_t */ +#define EGRAPH_EDGES_MAX 16384 /* cannot be more that u_int32_t */ + +typedef struct Egraph Egraph; +typedef struct Egraph_Edge Egraph_Edge; +typedef struct Egraph_Vertice Egraph_Vertice; + +struct Egraph { + Evas_Object *container; + igraph_t graph; + int graph_directed; + Egraph_Vertice *vertices[EGRAPH_VERTICES_MAX]; + int vertices_count; + u_int32_t vertices_freeids[EGRAPH_VERTICES_MAX]; + Eina_List *edges; + char *layout; // XXX +}; + +struct Egraph_Vertice { + u_int32_t id; + int vertice_id; + Evas_Object *o; + void *data; +}; + +struct Egraph_Edge { + Egraph_Vertice *a; + Egraph_Vertice *b; + Evas_Object *o; + void *data; +}; + +Egraph *egraph_new(Evas_Object *container, int directed); +void egraph_free(Egraph *eg); +int egraph_layout_set(Egraph *eg, const char *layout); + +Egraph_Edge *egraph_edge_add(Egraph *eg, + Egraph_Vertice *a, Egraph_Vertice *b, void *data); +void egraph_edge_del(Egraph *eg, Egraph_Edge *e); + +Egraph_Vertice *egraph_vertice_add(Egraph *eg, void *data); +void egraph_vertice_del(Egraph *eg, Egraph_Vertice *v); + + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..29b136c --- /dev/null +++ b/Makefile @@ -0,0 +1,28 @@ +CFLAGS += -Wall -O2 -fPIC -shared +CFLAGS += $(shell pkg-config --libs --cflags igraph) +CFLAGS += $(shell pkg-config --libs --cflags efx) + +PREFIX=/usr/local +INCLUDEDIR=$(PREFIX)/include +LIBDIR=$(PREFIX)/lib +LIBNAME=egraph + +TARGET = ${LIBNAME}.so +SOURCES = egraph.c +HEADERS = Egraph.h +OBJECTS = $(SOURCES:.c=.o) + +all: $(TARGET) + +$(TARGET): $(OBJECTS) + $(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS) + +install: + @echo "installation of $(LIBNAME)" + mkdir -p $(LIBDIR) + mkdir -p $(INCLUDEDIR) + install -m 0644 $(TARGET) $(LIBDIR) + install -m 0644 $(HEADERS) $(INCLUDEDIR) + +clean: + rm -f $(TARGET) $(OBJECTS) diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..40649ed --- /dev/null +++ b/README.txt @@ -0,0 +1,16 @@ +egraph - library for rendring dynamic graphs in an evas_smart_object + +Requirements +============ + +* eina +* evas +* ecore +* efx +* igraph + +Installation +============ + +make +sudo make install diff --git a/egraph.c b/egraph.c new file mode 100644 index 0000000..8316e9f --- /dev/null +++ b/egraph.c @@ -0,0 +1,184 @@ +#include + +#include "Egraph.h" + +static void _recalc(Egraph *eg); + +Egraph * +egraph_new(Evas_Object *container, int directed) +{ + Egraph *eg; + int i; + + eg = calloc(1, sizeof(Egraph)); + if (!eg) + goto err; + + if (igraph_empty(&eg->graph, 0, directed)) + goto err; + eg->graph_directed = directed; + for (i=0; ivertices_freeids[i] = i; + + if (container) { + //eg->container = container; + // XXX evas + } + + return eg; + +err: + if (eg) + egraph_free(eg); + return NULL; +} + +void +egraph_free(Egraph *eg) +{ + igraph_destroy(&eg->graph); +} + +/* + * Adds an edge between existing vertices + * XXX make a function that creates the missing vertices to avoid dual recalc + */ +Egraph_Edge * +egraph_edge_add(Egraph *eg, Egraph_Vertice *a, Egraph_Vertice *b, void *data) +{ + Egraph_Edge *e; + + e = malloc(sizeof(Egraph_Edge)); + if (!e) + goto err;; + + igraph_add_edge(&eg->graph, a->vertice_id, b->vertice_id); + + if (eg->container) { + // XXX evas e->o = ; + } + + e->data = data; + eg->edges = eina_list_append(eg->edges, e); + _recalc(eg); + return e; + +err: + if (e) + egraph_edge_del(eg, e); + return NULL; +} + +/* + * Delete an edge + * This does not delete vertices + */ +void +egraph_edge_del(Egraph *eg, Egraph_Edge *e) +{ + igraph_es_t es; + + igraph_es_pairs_small(&es, eg->graph_directed, + e->a->vertice_id, e->b->vertice_id, -1); + igraph_delete_edges(&eg->graph, es); + + if (e->o) { + // XXX evas + } + + eg->edges = eina_list_remove(eg->edges, e); + free(e); + _recalc(eg); +} + +Egraph_Vertice * +egraph_vertice_add(Egraph *eg, void *data) +{ + Egraph_Vertice *v; + + v = malloc(sizeof(Egraph_Vertice)); + if (!v) + return NULL; + if (eg->vertices_count == EGRAPH_VERTICES_MAX) { + printf("egraph error: maximum number of vertices reached !\n"); + goto err; + } + v->id = eg->vertices_freeids[eg->vertices_count]; + eg->vertices[v->id] = v; + + igraph_add_vertices(&eg->graph, 1, 0); + v->vertice_id = eg->vertices_count; + SETVAN(&eg->graph, "id", eg->vertices_count, v->id); + eg->vertices_count++; + + if (eg->container) { + // XXX evas v->o = ; + } + + v->data = data; + _recalc(eg); + return v; + +err: + if (v) + egraph_vertice_del(eg, v); + return NULL; +} + +/* + * Delete a vertice + * Also deletes all the edges attached to it + */ +void +egraph_vertice_del(Egraph *eg, Egraph_Vertice *v) +{ + Egraph_Edge *e; + Eina_List *l; + + EINA_LIST_FOREACH(eg->edges, l, e) + if (e->a == v || e->b == v) + egraph_edge_del(eg, e); + + igraph_delete_vertices(&eg->graph, igraph_vss_1(v->vertice_id)); + + if (v->o) { + // XXX evas + } + + eg->vertices_count--; + eg->vertices_freeids[eg->vertices_count] = v->id; + free(v); + _recalc(eg); +} + +int +egraph_layout_set(Egraph *eg, const char *layout) +{ + if (eg->layout) + free(eg->layout); + eg->layout = strndup(layout, 20); + + return 0; +} + +static void _recalc(Egraph *eg) +{ + igraph_matrix_t coords; + int i, n; + u_int32_t id; + + igraph_matrix_init(&coords, eg->vertices_count, 2); + igraph_layout_reingold_tilford(&eg->graph, &coords, IGRAPH_IN, 0, 0); + + // XXX DEBUG + n = igraph_vcount(&eg->graph); + if (n != eg->vertices_count) + err(1, "err: n (%d) != vertices_count (%d)\n", n, eg->vertices_count); + + for (i=0; igraph, "id", i); + // XXX evas + printf("%d: %6.3f %6.3f id %d\n", + i, MATRIX(coords, i, 0), MATRIX(coords, i, 1), id); + } +} -- cgit v1.2.3-59-g8ed1b From 0fd1bd143a1ca92f3a338e09ccf23281009d1e45 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 03:38:01 +0100 Subject: add WARNING about work in progress --- README.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.txt b/README.txt index 40649ed..28c4784 100644 --- a/README.txt +++ b/README.txt @@ -1,5 +1,7 @@ egraph - library for rendring dynamic graphs in an evas_smart_object +WARNING: Development in progress, don't expect this to work ! + Requirements ============ -- cgit v1.2.3-59-g8ed1b From 2877a55fe55cf70c416f045726691b63f299eeec Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 04:23:36 +0100 Subject: add unit test --- tests/Makefile | 32 ++++++++++++++++++++++++++++++++ tests/README.txt | 4 ++++ tests/creategraph.c | 20 ++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 tests/Makefile create mode 100644 tests/README.txt create mode 100644 tests/creategraph.c diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..d25fc13 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,32 @@ +CFLAGS += -Wall -g +CFLAGS += $(shell pkg-config --libs --cflags igraph) +CFLAGS += $(shell pkg-config --libs --cflags efx) +CFLAGS += -L../ -legraph + +SOURCES = $(shell echo *.c) +OBJECTS = $(SOURCES:.c=.o) +TARGETS = $(SOURCES:.c=) + +all: $(TARGETS) + +run: $(TARGETS) + @count=0 ;\ + errors=0 ;\ + for test in $(TARGETS); do \ + echo =============================================================================== ;\ + echo $$test ;\ + LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:../ ./$$test ;\ + if [ $$? -eq 0 ]; then \ + echo OK ;\ + else \ + echo FAILED ;\ + errors=$$(($$errors + 1)) ;\ + fi ;\ + count=$$(($$count + 1)) ;\ + done ;\ + echo =============================================================================== ;\ + echo "$$count tests executed, $$errors errors" ;\ + exit $$errors + +clean: + rm -f $(TARGETS) $(OBJECTS) diff --git a/tests/README.txt b/tests/README.txt new file mode 100644 index 0000000..9a25111 --- /dev/null +++ b/tests/README.txt @@ -0,0 +1,4 @@ +egraph library unit tests + +do "make run" to execute them +returns the number of tests that failed diff --git a/tests/creategraph.c b/tests/creategraph.c new file mode 100644 index 0000000..215d010 --- /dev/null +++ b/tests/creategraph.c @@ -0,0 +1,20 @@ +#include "../Egraph.h" + +int +main(void) +{ + Egraph *eg; + Egraph_Vertice *a, *b; + Egraph_Edge *e; + + eg = egraph_new(NULL, 1); + + a = egraph_vertice_add(eg, NULL); + b = egraph_vertice_add(eg, NULL); + e = egraph_edge_add(eg, a, b, NULL); + egraph_vertice_del(eg, a); + + egraph_free(eg); + + return (!eg); +} -- cgit v1.2.3-59-g8ed1b From 02ba954cf4a1df88497917aa97b95e104c038a3c Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 04:24:36 +0100 Subject: add -g to CFLAGS --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 29b136c..c130dab 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS += -Wall -O2 -fPIC -shared +CFLAGS += -Wall -O2 -fPIC -shared -g CFLAGS += $(shell pkg-config --libs --cflags igraph) CFLAGS += $(shell pkg-config --libs --cflags efx) -- cgit v1.2.3-59-g8ed1b From 0bd7e6d4f7f3ab21dc0073c18a8dd42cecb7e516 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 04:24:45 +0100 Subject: compile lib as libegraph --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c130dab..55ccfe4 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CFLAGS += $(shell pkg-config --libs --cflags efx) PREFIX=/usr/local INCLUDEDIR=$(PREFIX)/include LIBDIR=$(PREFIX)/lib -LIBNAME=egraph +LIBNAME=libegraph TARGET = ${LIBNAME}.so SOURCES = egraph.c -- cgit v1.2.3-59-g8ed1b From b5ba7e58bd318810f09bd96e7919608ab65491e2 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 04:25:02 +0100 Subject: oops, forgot to init eina and igraph attributes --- egraph.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/egraph.c b/egraph.c index 8316e9f..eb4c2e9 100644 --- a/egraph.c +++ b/egraph.c @@ -10,6 +10,11 @@ egraph_new(Evas_Object *container, int directed) Egraph *eg; int i; + eina_init(); + + /* needed for igraph attribute handling */ + igraph_i_set_attribute_table(&igraph_cattribute_table); + eg = calloc(1, sizeof(Egraph)); if (!eg) goto err; -- cgit v1.2.3-59-g8ed1b From f07dffda05d6ee2a217e9662ff53d433b37b3f13 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 04:25:29 +0100 Subject: add debug printf --- egraph.c | 1 + 1 file changed, 1 insertion(+) diff --git a/egraph.c b/egraph.c index eb4c2e9..2a483db 100644 --- a/egraph.c +++ b/egraph.c @@ -180,6 +180,7 @@ static void _recalc(Egraph *eg) if (n != eg->vertices_count) err(1, "err: n (%d) != vertices_count (%d)\n", n, eg->vertices_count); + printf("[-] _recalc\n"); for (i=0; igraph, "id", i); // XXX evas -- cgit v1.2.3-59-g8ed1b From b94b1affa61776ceddc9df498c6169ba3656688f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 04:26:50 +0100 Subject: remove extra blank line --- Egraph.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Egraph.h b/Egraph.h index 502b64d..da00700 100644 --- a/Egraph.h +++ b/Egraph.h @@ -45,4 +45,3 @@ void egraph_edge_del(Egraph *eg, Egraph_Edge *e); Egraph_Vertice *egraph_vertice_add(Egraph *eg, void *data); void egraph_vertice_del(Egraph *eg, Egraph_Vertice *v); - -- cgit v1.2.3-59-g8ed1b From 3a13dd73d5bda892b574db4eb65db8e18e4f0983 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 04:28:10 +0100 Subject: XXX ++ --- egraph.c | 1 + 1 file changed, 1 insertion(+) diff --git a/egraph.c b/egraph.c index 2a483db..9ccc129 100644 --- a/egraph.c +++ b/egraph.c @@ -133,6 +133,7 @@ err: /* * Delete a vertice * Also deletes all the edges attached to it + * XXX add user callback where edges are deleted */ void egraph_vertice_del(Egraph *eg, Egraph_Vertice *v) -- cgit v1.2.3-59-g8ed1b From ef5c8cb312b7e0a4dd1f5bda89d4c3d1e7febd04 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 05:29:43 +0100 Subject: fix missing assignements and eina_list handling --- egraph.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index 9ccc129..c9ad2eb 100644 --- a/egraph.c +++ b/egraph.c @@ -57,6 +57,8 @@ egraph_edge_add(Egraph *eg, Egraph_Vertice *a, Egraph_Vertice *b, void *data) if (!e) goto err;; + e->a = a; + e->b = b; igraph_add_edge(&eg->graph, a->vertice_id, b->vertice_id); if (eg->container) { @@ -139,9 +141,9 @@ void egraph_vertice_del(Egraph *eg, Egraph_Vertice *v) { Egraph_Edge *e; - Eina_List *l; + Eina_List *l, *lprev; - EINA_LIST_FOREACH(eg->edges, l, e) + EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) if (e->a == v || e->b == v) egraph_edge_del(eg, e); -- cgit v1.2.3-59-g8ed1b From 5669a7e4929a204837073e085bafd98fc02bdd6a Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 10:40:37 +0100 Subject: example of possible future API --- Egraph.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Egraph.h b/Egraph.h index da00700..e5e0d02 100644 --- a/Egraph.h +++ b/Egraph.h @@ -45,3 +45,15 @@ void egraph_edge_del(Egraph *eg, Egraph_Edge *e); Egraph_Vertice *egraph_vertice_add(Egraph *eg, void *data); void egraph_vertice_del(Egraph *eg, Egraph_Vertice *v); +/* XXX possible future API: no edges no vertices */ +/* +struct Egraph_Vertice { + const char *name; + int vertice_id; + Evas_Object *o; + void *data; +} +egraph_vertice_add(Egraph *eg, const char *name, void *data); +egraph_edge_add(Egraph *eg, + const char *a, const char *b, void *data); +*/ -- cgit v1.2.3-59-g8ed1b From 98615e6944534e880f43e319904316034d45fa23 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 13:17:46 +0100 Subject: make Egraph an evas_smart_object --- Egraph.h | 16 ++++----- egraph.c | 116 +++++++++++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 88 insertions(+), 44 deletions(-) diff --git a/Egraph.h b/Egraph.h index e5e0d02..217dba2 100644 --- a/Egraph.h +++ b/Egraph.h @@ -10,7 +10,8 @@ typedef struct Egraph_Edge Egraph_Edge; typedef struct Egraph_Vertice Egraph_Vertice; struct Egraph { - Evas_Object *container; + Evas_Object_Smart_Clipped_Data __clipped_data; + Evas *evas; igraph_t graph; int graph_directed; Egraph_Vertice *vertices[EGRAPH_VERTICES_MAX]; @@ -34,16 +35,15 @@ struct Egraph_Edge { void *data; }; -Egraph *egraph_new(Evas_Object *container, int directed); -void egraph_free(Egraph *eg); -int egraph_layout_set(Egraph *eg, const char *layout); +Evas_Object *egraph_new(Evas *evas, int directed); +int egraph_layout_set(Evas_Object *obj, const char *layout); -Egraph_Edge *egraph_edge_add(Egraph *eg, +Egraph_Edge *egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, void *data); -void egraph_edge_del(Egraph *eg, Egraph_Edge *e); +void egraph_edge_del(Evas_Object *obj, Egraph_Edge *e); -Egraph_Vertice *egraph_vertice_add(Egraph *eg, void *data); -void egraph_vertice_del(Egraph *eg, Egraph_Vertice *v); +Egraph_Vertice *egraph_vertice_add(Evas_Object *obj, void *data); +void egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v); /* XXX possible future API: no edges no vertices */ /* diff --git a/egraph.c b/egraph.c index c9ad2eb..b63ca36 100644 --- a/egraph.c +++ b/egraph.c @@ -3,54 +3,96 @@ #include "Egraph.h" static void _recalc(Egraph *eg); +static void _smart_add(Evas_Object *obj); +static void _smart_del(Evas_Object *obj); +static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); +static void _smart_calculate(Evas_Object *obj); + +static const Evas_Smart_Cb_Description _smart_callbacks[] = {{NULL, NULL}}; +#define EGRAPH_DATA_GET(o, ptr) \ + Egraph * ptr = evas_object_smart_data_get(o) +/* defines _egraph_parent_sc and _egraph_smart_class_new */ +EVAS_SMART_SUBCLASS_NEW("Egraph", _egraph, + Evas_Smart_Class, Evas_Smart_Class, + evas_object_smart_clipped_class_get, _smart_callbacks); + +static void +_egraph_smart_set_user(Evas_Smart_Class *sc) +{ + /* specializing these two */ + sc->add = _smart_add; + sc->del = _smart_del; + /* clipped smart object has no hook on resizes or calculations */ + sc->resize = _smart_resize; + sc->calculate = _smart_calculate; +} + +static void +_smart_add(Evas_Object *obj) +{ + EVAS_SMART_DATA_ALLOC(obj, Egraph); + + _egraph_parent_sc->add(obj); +} + +static void +_smart_del(Evas_Object *obj) +{ + EGRAPH_DATA_GET(obj, eg); -Egraph * -egraph_new(Evas_Object *container, int directed) + igraph_destroy(&eg->graph); + _egraph_parent_sc->del(obj); +} + +static void +_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h) +{ +} + +static void +_smart_calculate(Evas_Object *obj) { +} + +Evas_Object * +egraph_new(Evas *evas, int directed) +{ + Evas_Object *obj = NULL; Egraph *eg; int i; - eina_init(); + EINA_SAFETY_ON_NULL_RETURN_VAL(evas, NULL); + + obj = evas_object_smart_add(evas, _egraph_smart_class_new()); + eg = evas_object_smart_data_get(obj); + if (!eg) goto err; /* needed for igraph attribute handling */ igraph_i_set_attribute_table(&igraph_cattribute_table); - eg = calloc(1, sizeof(Egraph)); - if (!eg) - goto err; - if (igraph_empty(&eg->graph, 0, directed)) goto err; eg->graph_directed = directed; for (i=0; ivertices_freeids[i] = i; - if (container) { - //eg->container = container; - // XXX evas - } - - return eg; + return obj; err: - if (eg) - egraph_free(eg); + if (obj) + evas_object_del(obj); return NULL; } -void -egraph_free(Egraph *eg) -{ - igraph_destroy(&eg->graph); -} - /* * Adds an edge between existing vertices * XXX make a function that creates the missing vertices to avoid dual recalc */ Egraph_Edge * -egraph_edge_add(Egraph *eg, Egraph_Vertice *a, Egraph_Vertice *b, void *data) +egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, + void *data) { + EGRAPH_DATA_GET(obj, eg); Egraph_Edge *e; e = malloc(sizeof(Egraph_Edge)); @@ -61,9 +103,7 @@ egraph_edge_add(Egraph *eg, Egraph_Vertice *a, Egraph_Vertice *b, void *data) e->b = b; igraph_add_edge(&eg->graph, a->vertice_id, b->vertice_id); - if (eg->container) { - // XXX evas e->o = ; - } + // XXX evas e->data = data; eg->edges = eina_list_append(eg->edges, e); @@ -72,7 +112,7 @@ egraph_edge_add(Egraph *eg, Egraph_Vertice *a, Egraph_Vertice *b, void *data) err: if (e) - egraph_edge_del(eg, e); + free(e); return NULL; } @@ -81,8 +121,9 @@ err: * This does not delete vertices */ void -egraph_edge_del(Egraph *eg, Egraph_Edge *e) +egraph_edge_del(Evas_Object *obj, Egraph_Edge *e) { + EGRAPH_DATA_GET(obj, eg); igraph_es_t es; igraph_es_pairs_small(&es, eg->graph_directed, @@ -99,8 +140,9 @@ egraph_edge_del(Egraph *eg, Egraph_Edge *e) } Egraph_Vertice * -egraph_vertice_add(Egraph *eg, void *data) +egraph_vertice_add(Evas_Object *obj, void *data) { + EGRAPH_DATA_GET(obj, eg); Egraph_Vertice *v; v = malloc(sizeof(Egraph_Vertice)); @@ -118,9 +160,7 @@ egraph_vertice_add(Egraph *eg, void *data) SETVAN(&eg->graph, "id", eg->vertices_count, v->id); eg->vertices_count++; - if (eg->container) { - // XXX evas v->o = ; - } + // XXX evas v->data = data; _recalc(eg); @@ -128,7 +168,7 @@ egraph_vertice_add(Egraph *eg, void *data) err: if (v) - egraph_vertice_del(eg, v); + free(v); return NULL; } @@ -138,14 +178,15 @@ err: * XXX add user callback where edges are deleted */ void -egraph_vertice_del(Egraph *eg, Egraph_Vertice *v) +egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v) { + EGRAPH_DATA_GET(obj, eg); Egraph_Edge *e; Eina_List *l, *lprev; EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) if (e->a == v || e->b == v) - egraph_edge_del(eg, e); + egraph_edge_del(obj, e); igraph_delete_vertices(&eg->graph, igraph_vss_1(v->vertice_id)); @@ -160,8 +201,10 @@ egraph_vertice_del(Egraph *eg, Egraph_Vertice *v) } int -egraph_layout_set(Egraph *eg, const char *layout) +egraph_layout_set(Evas_Object *obj, const char *layout) { + EGRAPH_DATA_GET(obj, eg); + if (eg->layout) free(eg->layout); eg->layout = strndup(layout, 20); @@ -169,7 +212,8 @@ egraph_layout_set(Egraph *eg, const char *layout) return 0; } -static void _recalc(Egraph *eg) +static void +_recalc(Egraph *eg) { igraph_matrix_t coords; int i, n; -- cgit v1.2.3-59-g8ed1b From 30bded7cb4e2a3e2f54062b844d5096022eaff35 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 13:18:03 +0100 Subject: update test to setup ecore_evas and use our brand new evas_smart_object --- tests/Makefile | 2 +- tests/creategraph.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index d25fc13..8b70170 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,7 +1,7 @@ CFLAGS += -Wall -g CFLAGS += $(shell pkg-config --libs --cflags igraph) CFLAGS += $(shell pkg-config --libs --cflags efx) -CFLAGS += -L../ -legraph +CFLAGS += -L../ -legraph -lecore_evas SOURCES = $(shell echo *.c) OBJECTS = $(SOURCES:.c=.o) diff --git a/tests/creategraph.c b/tests/creategraph.c index 215d010..11c1a65 100644 --- a/tests/creategraph.c +++ b/tests/creategraph.c @@ -1,20 +1,37 @@ +#include +#include +#include +#include + #include "../Egraph.h" int main(void) { - Egraph *eg; + Ecore_Evas *ee; + Evas *evas; + Evas_Object *obj = NULL; Egraph_Vertice *a, *b; Egraph_Edge *e; - eg = egraph_new(NULL, 1); + if (!ecore_evas_init()) + return EXIT_FAILURE; + ee = ecore_evas_new(NULL, 10, 10, 100, 100, NULL); + if (!ee) + return -1; + ecore_evas_show(ee); + evas = ecore_evas_get(ee); + + obj = egraph_new(evas, 1); - a = egraph_vertice_add(eg, NULL); - b = egraph_vertice_add(eg, NULL); - e = egraph_edge_add(eg, a, b, NULL); - egraph_vertice_del(eg, a); + a = egraph_vertice_add(obj, NULL); + b = egraph_vertice_add(obj, NULL); + e = egraph_edge_add(obj, a, b, NULL); + egraph_vertice_del(obj, a); - egraph_free(eg); + evas_object_del(obj); + ecore_evas_free(ee); + ecore_evas_shutdown(); - return (!eg); + return (!obj); } -- cgit v1.2.3-59-g8ed1b From 0bfe408d12eeee136c5e97a64292fe0a35ce0d91 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 13:19:03 +0100 Subject: wording --- README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.txt b/README.txt index 28c4784..e7c128e 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -egraph - library for rendring dynamic graphs in an evas_smart_object +egraph - library for rendring dynamic graphs in evas WARNING: Development in progress, don't expect this to work ! -- cgit v1.2.3-59-g8ed1b From 2764c2e4fbce50294e78253ca5213f2df4bf66d8 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 13:20:12 +0100 Subject: add example demo graph, not functionnal yet --- examples/Makefile | 13 ++++++++++++ examples/demograph.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 examples/Makefile create mode 100644 examples/demograph.c diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..8a45c33 --- /dev/null +++ b/examples/Makefile @@ -0,0 +1,13 @@ +CFLAGS += -Wall -g +CFLAGS += $(shell pkg-config --libs --cflags igraph) +CFLAGS += $(shell pkg-config --libs --cflags efx) +CFLAGS += -L../ -legraph -lecore_evas + +SOURCES = $(shell echo *.c) +OBJECTS = $(SOURCES:.c=.o) +TARGETS = $(SOURCES:.c=) + +all: $(TARGETS) + +clean: + rm -f $(TARGETS) $(OBJECTS) diff --git a/examples/demograph.c b/examples/demograph.c new file mode 100644 index 0000000..737809f --- /dev/null +++ b/examples/demograph.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include + +#include "../Egraph.h" + +static void +_on_destroy(Ecore_Evas *ee) +{ + ecore_main_loop_quit(); +} + +/* here just to keep our example's window size and background image's + * size in synchrony */ +static void +_canvas_resize_cb(Ecore_Evas *ee) +{ + int w, h; + +// ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); +// evas_object_resize(bg, w, h); +} + +int +main(void) +{ + Ecore_Evas *ee; + Evas *evas; + Evas_Object *obj = NULL; + Egraph_Vertice *a, *b; + Egraph_Edge *e; + + if (!ecore_evas_init()) + return EXIT_FAILURE; + ee = ecore_evas_new(NULL, 10, 10, 100, 100, NULL); + if (!ee) + return -1; + ecore_evas_callback_destroy_set(ee, _on_destroy); + ecore_evas_callback_resize_set(ee, _canvas_resize_cb); + ecore_evas_show(ee); + evas = ecore_evas_get(ee); + + obj = egraph_new(evas, 1); + + a = egraph_vertice_add(obj, NULL); + b = egraph_vertice_add(obj, NULL); + e = egraph_edge_add(obj, a, b, NULL); + egraph_vertice_del(obj, a); + + ecore_main_loop_begin(); + + evas_object_del(obj); + ecore_evas_free(ee); + ecore_evas_shutdown(); + + return (!obj); +} -- cgit v1.2.3-59-g8ed1b From c07c6095851cc813a9651f39c52b30afc23473f1 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 13:30:31 +0100 Subject: compile with -Werror --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 55ccfe4..4c52e96 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -CFLAGS += -Wall -O2 -fPIC -shared -g +CFLAGS += -Werror -Wall -O2 -fPIC -shared -g CFLAGS += $(shell pkg-config --libs --cflags igraph) CFLAGS += $(shell pkg-config --libs --cflags efx) -- cgit v1.2.3-59-g8ed1b From faed2c59c476c47a7e90fce0ae59a7e19454dd58 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 13:31:03 +0100 Subject: remove -O2 for now --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4c52e96..eae2587 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -CFLAGS += -Werror -Wall -O2 -fPIC -shared -g +# CFLAGS += -Werror -Wall -O2 -fPIC -shared -g +CFLAGS += -Werror -Wall -fPIC -shared -g CFLAGS += $(shell pkg-config --libs --cflags igraph) CFLAGS += $(shell pkg-config --libs --cflags efx) -- cgit v1.2.3-59-g8ed1b From 278c6a69390ab024c388ce1719b6a36a0d3cbbfe Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 13:43:27 +0100 Subject: small helper script when developping --- retest.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 retest.sh diff --git a/retest.sh b/retest.sh new file mode 100755 index 0000000..3561c30 --- /dev/null +++ b/retest.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +make clean && \ + make && \ + sudo make install && \ + make -C tests/ clean && \ + make -C tests/ run && \ + make -C examples && \ + ./examples/demograph -- cgit v1.2.3-59-g8ed1b From 9fa867246c21490c52f917a307fb361dc45a230d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 14:09:18 +0100 Subject: resize egraph object to window size --- examples/demograph.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/examples/demograph.c b/examples/demograph.c index 737809f..1d5aab7 100644 --- a/examples/demograph.c +++ b/examples/demograph.c @@ -5,21 +5,22 @@ #include "../Egraph.h" +Evas_Object *_egraph_obj = NULL; + static void _on_destroy(Ecore_Evas *ee) { ecore_main_loop_quit(); } -/* here just to keep our example's window size and background image's - * size in synchrony */ static void _canvas_resize_cb(Ecore_Evas *ee) { int w, h; -// ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); -// evas_object_resize(bg, w, h); + printf("_canvas_resize_cb\n"); + ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); + evas_object_resize(_egraph_obj, w, h); } int @@ -27,7 +28,6 @@ main(void) { Ecore_Evas *ee; Evas *evas; - Evas_Object *obj = NULL; Egraph_Vertice *a, *b; Egraph_Edge *e; @@ -41,18 +41,19 @@ main(void) ecore_evas_show(ee); evas = ecore_evas_get(ee); - obj = egraph_new(evas, 1); + _egraph_obj = egraph_new(evas, 1); + evas_object_resize(_egraph_obj, 100, 100); + evas_object_show(_egraph_obj); - a = egraph_vertice_add(obj, NULL); - b = egraph_vertice_add(obj, NULL); - e = egraph_edge_add(obj, a, b, NULL); - egraph_vertice_del(obj, a); + a = egraph_vertice_add(_egraph_obj, NULL); + b = egraph_vertice_add(_egraph_obj, NULL); + e = egraph_edge_add(_egraph_obj, a, b, NULL); ecore_main_loop_begin(); - evas_object_del(obj); + evas_object_del(_egraph_obj); ecore_evas_free(ee); ecore_evas_shutdown(); - return (!obj); + return (!_egraph_obj); } -- cgit v1.2.3-59-g8ed1b From 1f6fe2d1bea465b2557425da8a4efe57da0758e2 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 14:09:41 +0100 Subject: create evas objects for edges and vertices, compute their size in _recalc() and show them --- egraph.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/egraph.c b/egraph.c index b63ca36..c2a9854 100644 --- a/egraph.c +++ b/egraph.c @@ -2,7 +2,7 @@ #include "Egraph.h" -static void _recalc(Egraph *eg); +static void _recalc(Evas_Object *obj); static void _smart_add(Evas_Object *obj); static void _smart_del(Evas_Object *obj); static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); @@ -32,6 +32,8 @@ _smart_add(Evas_Object *obj) { EVAS_SMART_DATA_ALLOC(obj, Egraph); + priv->evas = evas_object_evas_get(obj); + _egraph_parent_sc->add(obj); } @@ -93,6 +95,7 @@ egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, void *data) { EGRAPH_DATA_GET(obj, eg); + Evas_Object *eobj; Egraph_Edge *e; e = malloc(sizeof(Egraph_Edge)); @@ -103,11 +106,14 @@ egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, e->b = b; igraph_add_edge(&eg->graph, a->vertice_id, b->vertice_id); - // XXX evas + eobj = evas_object_line_add(eg->evas); + evas_object_smart_member_add(eobj, obj); + evas_object_color_set(eobj, 255, 0, 0, 255); + e->o = eobj; e->data = data; eg->edges = eina_list_append(eg->edges, e); - _recalc(eg); + _recalc(obj); return e; err: @@ -136,7 +142,7 @@ egraph_edge_del(Evas_Object *obj, Egraph_Edge *e) eg->edges = eina_list_remove(eg->edges, e); free(e); - _recalc(eg); + _recalc(obj); } Egraph_Vertice * @@ -144,6 +150,7 @@ egraph_vertice_add(Evas_Object *obj, void *data) { EGRAPH_DATA_GET(obj, eg); Egraph_Vertice *v; + Evas_Object *vobj; v = malloc(sizeof(Egraph_Vertice)); if (!v) @@ -160,10 +167,14 @@ egraph_vertice_add(Evas_Object *obj, void *data) SETVAN(&eg->graph, "id", eg->vertices_count, v->id); eg->vertices_count++; - // XXX evas + vobj = evas_object_rectangle_add(eg->evas); + evas_object_smart_member_add(vobj, obj); + evas_object_color_set(vobj, 255, 255, 255, 255); + evas_object_resize(vobj, 10, 10); + v->o = vobj; v->data = data; - _recalc(eg); + _recalc(obj); return v; err: @@ -197,7 +208,7 @@ egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v) eg->vertices_count--; eg->vertices_freeids[eg->vertices_count] = v->id; free(v); - _recalc(eg); + _recalc(obj); } int @@ -213,14 +224,30 @@ egraph_layout_set(Evas_Object *obj, const char *layout) } static void -_recalc(Egraph *eg) +_recalc(Evas_Object *obj) { + EGRAPH_DATA_GET(obj, eg); + Egraph_Vertice *v; + Egraph_Edge *e; + Eina_List *l; igraph_matrix_t coords; + float x, y; int i, n; + int obj_x, obj_y, obj_w, obj_h; + int x1, x2, y1, y2; u_int32_t id; + int size_max; + int size_factor; + + evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h); igraph_matrix_init(&coords, eg->vertices_count, 2); - igraph_layout_reingold_tilford(&eg->graph, &coords, IGRAPH_IN, 0, 0); + igraph_layout_reingold_tilford(&eg->graph, &coords, IGRAPH_IN, 0, 0); + size_max = igraph_matrix_max(&coords); // XXX do per vertor + if (size_max && obj_w) + size_factor = obj_w / size_max; + else + size_factor = 1; // XXX DEBUG n = igraph_vcount(&eg->graph); @@ -228,10 +255,25 @@ _recalc(Egraph *eg) err(1, "err: n (%d) != vertices_count (%d)\n", n, eg->vertices_count); printf("[-] _recalc\n"); + for (i=0; igraph, "id", i); - // XXX evas - printf("%d: %6.3f %6.3f id %d\n", - i, MATRIX(coords, i, 0), MATRIX(coords, i, 1), id); + x = MATRIX(coords, i, 0); + y = MATRIX(coords, i, 1); + printf("%d: %6.3f %6.3f id %d\n", i, x, y, id); + x = (x * size_factor) / 2 + (obj_w/2); + y = (y * size_factor) / 2 + (obj_h/2); + printf(" inobj: %6.3f %6.3f id %d\n", x, y, id); + + v = eg->vertices[id]; + evas_object_move(v->o, x, y); + evas_object_show(v->o); + } + + EINA_LIST_FOREACH(eg->edges, l, e) { + evas_object_geometry_get(e->a->o, &x1, &y1, NULL, NULL); + evas_object_geometry_get(e->b->o, &x2, &y2, NULL, NULL); + evas_object_line_xy_set(e->o, x1, y1, x1, y2); + evas_object_show(e->o); } } -- cgit v1.2.3-59-g8ed1b From b0dba95c422dd2e25adbf0bcb42cad86dded88cb Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 14:20:41 +0100 Subject: move the functions documentation to Egraph.h in Doxygen format --- Egraph.h | 36 +++++++++++++++++++++++++++++++++++- egraph.c | 13 ------------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/Egraph.h b/Egraph.h index 217dba2..124e061 100644 --- a/Egraph.h +++ b/Egraph.h @@ -35,17 +35,51 @@ struct Egraph_Edge { void *data; }; +/** + * Creates Egraph Evas_Object + */ Evas_Object *egraph_new(Evas *evas, int directed); + +/** + * Sets the layout of Egraph + * + * @warning XXX not functionnal + */ int egraph_layout_set(Evas_Object *obj, const char *layout); +/** + * Adds an edge between existing vertices + * + * @param obj The Egraph object + * @param a First vertice + * @param b Second vertice + * @param data The pointer to attach + * @return The new Egraph_Egde object + * @todo XXX make a function that creates the missing vertices to avoid dual recalc + */ Egraph_Edge *egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, void *data); + +/** + * Delete an edge + * + * Hint: This does not delete vertices + */ void egraph_edge_del(Evas_Object *obj, Egraph_Edge *e); Egraph_Vertice *egraph_vertice_add(Evas_Object *obj, void *data); + +/** + * Delete a vertice + * + * Hint: Also deletes all the edges attached to it + * + * @param obj The Egraph object + * @todo add user callback where edges are deleted + */ void egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v); -/* XXX possible future API: no edges no vertices */ +/* XXX possible future API: no edges no vertices for the user */ /* struct Egraph_Vertice { const char *name; diff --git a/egraph.c b/egraph.c index c2a9854..8a91cca 100644 --- a/egraph.c +++ b/egraph.c @@ -86,10 +86,6 @@ err: return NULL; } -/* - * Adds an edge between existing vertices - * XXX make a function that creates the missing vertices to avoid dual recalc - */ Egraph_Edge * egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, void *data) @@ -122,10 +118,6 @@ err: return NULL; } -/* - * Delete an edge - * This does not delete vertices - */ void egraph_edge_del(Evas_Object *obj, Egraph_Edge *e) { @@ -183,11 +175,6 @@ err: return NULL; } -/* - * Delete a vertice - * Also deletes all the edges attached to it - * XXX add user callback where edges are deleted - */ void egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v) { -- cgit v1.2.3-59-g8ed1b From 938dc3c8d6cdc3794c88350d971c2e5acbce3108 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 14:21:40 +0100 Subject: delete evas objects on egde / vertice deletion --- egraph.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/egraph.c b/egraph.c index 8a91cca..9a6954f 100644 --- a/egraph.c +++ b/egraph.c @@ -128,9 +128,7 @@ egraph_edge_del(Evas_Object *obj, Egraph_Edge *e) e->a->vertice_id, e->b->vertice_id, -1); igraph_delete_edges(&eg->graph, es); - if (e->o) { - // XXX evas - } + evas_object_del(e->o); eg->edges = eina_list_remove(eg->edges, e); free(e); @@ -188,9 +186,7 @@ egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v) igraph_delete_vertices(&eg->graph, igraph_vss_1(v->vertice_id)); - if (v->o) { - // XXX evas - } + evas_object_del(v->o); eg->vertices_count--; eg->vertices_freeids[eg->vertices_count] = v->id; -- cgit v1.2.3-59-g8ed1b From 61d4a6fd389162926c7c28f7d5cd5cebf5779bcc Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 14:42:42 +0100 Subject: remove useless define --- Egraph.h | 1 - 1 file changed, 1 deletion(-) diff --git a/Egraph.h b/Egraph.h index 124e061..50d4674 100644 --- a/Egraph.h +++ b/Egraph.h @@ -3,7 +3,6 @@ #include #define EGRAPH_VERTICES_MAX 16384 /* cannot be more that u_int32_t */ -#define EGRAPH_EDGES_MAX 16384 /* cannot be more that u_int32_t */ typedef struct Egraph Egraph; typedef struct Egraph_Edge Egraph_Edge; -- cgit v1.2.3-59-g8ed1b From db2bdc0ba67617229975229a3f2570da71f2ee27 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 14:52:09 +0100 Subject: forgot to clean examples/ --- retest.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/retest.sh b/retest.sh index 3561c30..789f35e 100755 --- a/retest.sh +++ b/retest.sh @@ -5,5 +5,6 @@ make clean && \ sudo make install && \ make -C tests/ clean && \ make -C tests/ run && \ + make -C examples clean && \ make -C examples && \ ./examples/demograph -- cgit v1.2.3-59-g8ed1b From 056a62033c74f4a951cc80d67d9de58324e30bd5 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 15:02:56 +0100 Subject: handle vertice names --- Egraph.h | 14 +++++++++++++- egraph.c | 23 +++++++++++++++++++++-- examples/demograph.c | 4 ++-- tests/creategraph.c | 4 ++-- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Egraph.h b/Egraph.h index 50d4674..2ec274b 100644 --- a/Egraph.h +++ b/Egraph.h @@ -3,6 +3,7 @@ #include #define EGRAPH_VERTICES_MAX 16384 /* cannot be more that u_int32_t */ +#define EGRAPH_VERTICE_NAME_MAXLEN 50 typedef struct Egraph Egraph; typedef struct Egraph_Edge Egraph_Edge; @@ -22,8 +23,10 @@ struct Egraph { struct Egraph_Vertice { u_int32_t id; + const char *name; int vertice_id; Evas_Object *o; + Evas_Object *o_text; void *data; }; @@ -66,7 +69,16 @@ Egraph_Edge *egraph_edge_add(Evas_Object *obj, */ void egraph_edge_del(Evas_Object *obj, Egraph_Edge *e); -Egraph_Vertice *egraph_vertice_add(Evas_Object *obj, void *data); +/** + * Add a vertice to the graph + * + * @param obj The Egraph object + * @param name The name of the vertice to be displayed. If NULL, no name is + * displayed + * @param data The pointer to attach + */ +Egraph_Vertice *egraph_vertice_add(Evas_Object *obj, + const char *name, void *data); /** * Delete a vertice diff --git a/egraph.c b/egraph.c index 9a6954f..7062e15 100644 --- a/egraph.c +++ b/egraph.c @@ -136,11 +136,11 @@ egraph_edge_del(Evas_Object *obj, Egraph_Edge *e) } Egraph_Vertice * -egraph_vertice_add(Evas_Object *obj, void *data) +egraph_vertice_add(Evas_Object *obj, const char *name, void *data) { EGRAPH_DATA_GET(obj, eg); Egraph_Vertice *v; - Evas_Object *vobj; + Evas_Object *vobj, *text; v = malloc(sizeof(Egraph_Vertice)); if (!v) @@ -149,6 +149,10 @@ egraph_vertice_add(Evas_Object *obj, void *data) printf("egraph error: maximum number of vertices reached !\n"); goto err; } + if (name) + v->name = strndup(name, EGRAPH_VERTICE_NAME_MAXLEN); + else + v->name = NULL; v->id = eg->vertices_freeids[eg->vertices_count]; eg->vertices[v->id] = v; @@ -162,6 +166,16 @@ egraph_vertice_add(Evas_Object *obj, void *data) evas_object_color_set(vobj, 255, 255, 255, 255); evas_object_resize(vobj, 10, 10); v->o = vobj; + if (name) { + text = evas_object_text_add(eg->evas); + evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); + evas_object_color_set(text, 0, 255, 0, 255); + evas_object_text_font_set(text, "Vera-Bold", 10); + evas_object_resize(text, 30, 30); // XXX + evas_object_text_text_set(text, name); + evas_object_smart_member_add(text, obj); + v->o_text = text; + } v->data = data; _recalc(obj); @@ -251,6 +265,11 @@ _recalc(Evas_Object *obj) v = eg->vertices[id]; evas_object_move(v->o, x, y); evas_object_show(v->o); + if (v->name) { + evas_object_move(v->o_text, x+3, y+8); + evas_object_show(v->o_text); + + } } EINA_LIST_FOREACH(eg->edges, l, e) { diff --git a/examples/demograph.c b/examples/demograph.c index 1d5aab7..43e6d59 100644 --- a/examples/demograph.c +++ b/examples/demograph.c @@ -45,8 +45,8 @@ main(void) evas_object_resize(_egraph_obj, 100, 100); evas_object_show(_egraph_obj); - a = egraph_vertice_add(_egraph_obj, NULL); - b = egraph_vertice_add(_egraph_obj, NULL); + a = egraph_vertice_add(_egraph_obj, "a", NULL); + b = egraph_vertice_add(_egraph_obj, "b", NULL); e = egraph_edge_add(_egraph_obj, a, b, NULL); ecore_main_loop_begin(); diff --git a/tests/creategraph.c b/tests/creategraph.c index 11c1a65..d27e3d5 100644 --- a/tests/creategraph.c +++ b/tests/creategraph.c @@ -24,8 +24,8 @@ main(void) obj = egraph_new(evas, 1); - a = egraph_vertice_add(obj, NULL); - b = egraph_vertice_add(obj, NULL); + a = egraph_vertice_add(obj, "a", NULL); + b = egraph_vertice_add(obj, NULL, NULL); e = egraph_edge_add(obj, a, b, NULL); egraph_vertice_del(obj, a); -- cgit v1.2.3-59-g8ed1b From 81beb269cdb2e945525e3f97542361daf4394555 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 15:11:17 +0100 Subject: more precisions in Requirements --- README.txt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/README.txt b/README.txt index e7c128e..b957ea3 100644 --- a/README.txt +++ b/README.txt @@ -5,11 +5,14 @@ WARNING: Development in progress, don't expect this to work ! Requirements ============ -* eina -* evas -* ecore -* efx -* igraph +* Enlightenment Foundation Libraries +http://www.enlightenment.org + * eina + * evas + * ecore + * efx + +* igraph - http://igraph.sourceforge.net/index.html Installation ============ -- cgit v1.2.3-59-g8ed1b From a8b65dfe725ff20529cda76474fbc2b7f8f80e93 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 15:59:26 +0100 Subject: fix vertices positionning, must be relative to the parent coordinates --- egraph.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/egraph.c b/egraph.c index 7062e15..92ffbf4 100644 --- a/egraph.c +++ b/egraph.c @@ -237,12 +237,13 @@ _recalc(Evas_Object *obj) int size_factor; evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h); + printf("egraph: %d %d %d %d\n", obj_x, obj_y, obj_w, obj_h); igraph_matrix_init(&coords, eg->vertices_count, 2); igraph_layout_reingold_tilford(&eg->graph, &coords, IGRAPH_IN, 0, 0); size_max = igraph_matrix_max(&coords); // XXX do per vertor - if (size_max && obj_w) - size_factor = obj_w / size_max; + if (size_max && obj_w && obj_w > size_max) + size_factor = (obj_w / size_max) * 0.8; else size_factor = 1; @@ -258,8 +259,8 @@ _recalc(Evas_Object *obj) x = MATRIX(coords, i, 0); y = MATRIX(coords, i, 1); printf("%d: %6.3f %6.3f id %d\n", i, x, y, id); - x = (x * size_factor) / 2 + (obj_w/2); - y = (y * size_factor) / 2 + (obj_h/2); + x = obj_x + (x * size_factor) / 2 + (obj_w/2); + y = obj_y + (y * size_factor) / 2 + (obj_h/2); printf(" inobj: %6.3f %6.3f id %d\n", x, y, id); v = eg->vertices[id]; -- cgit v1.2.3-59-g8ed1b From fdfd8cf4c259bf3d197076fd61bd2581bb3892e7 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 16:13:57 +0100 Subject: do not specify final exec --- retest.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/retest.sh b/retest.sh index 789f35e..c778fa1 100755 --- a/retest.sh +++ b/retest.sh @@ -6,5 +6,4 @@ make clean && \ make -C tests/ clean && \ make -C tests/ run && \ make -C examples clean && \ - make -C examples && \ - ./examples/demograph + make -C examples -- cgit v1.2.3-59-g8ed1b From 109f10274bc23b30a8ddb475f5c1d0a13b84a532 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 16:23:21 +0100 Subject: we need elementary, not efx or igraph --- examples/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/Makefile b/examples/Makefile index 8a45c33..9ac573e 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,6 +1,5 @@ CFLAGS += -Wall -g -CFLAGS += $(shell pkg-config --libs --cflags igraph) -CFLAGS += $(shell pkg-config --libs --cflags efx) +CFLAGS += $(shell pkg-config --libs --cflags elementary) CFLAGS += -L../ -legraph -lecore_evas SOURCES = $(shell echo *.c) -- cgit v1.2.3-59-g8ed1b From b124b741cc7246366e22ec1bbfcedfd79958c9bb Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 16:34:40 +0100 Subject: change layout to igraph_layout_kamada_kawai with persistent seed --- Egraph.h | 1 + egraph.c | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Egraph.h b/Egraph.h index 2ec274b..5f3063e 100644 --- a/Egraph.h +++ b/Egraph.h @@ -14,6 +14,7 @@ struct Egraph { Evas *evas; igraph_t graph; int graph_directed; + igraph_matrix_t graph_coords; Egraph_Vertice *vertices[EGRAPH_VERTICES_MAX]; int vertices_count; u_int32_t vertices_freeids[EGRAPH_VERTICES_MAX]; diff --git a/egraph.c b/egraph.c index 92ffbf4..a4912ef 100644 --- a/egraph.c +++ b/egraph.c @@ -74,6 +74,7 @@ egraph_new(Evas *evas, int directed) if (igraph_empty(&eg->graph, 0, directed)) goto err; + igraph_matrix_init(&eg->graph_coords, 0, 2); eg->graph_directed = directed; for (i=0; ivertices_freeids[i] = i; @@ -227,7 +228,6 @@ _recalc(Evas_Object *obj) Egraph_Vertice *v; Egraph_Edge *e; Eina_List *l; - igraph_matrix_t coords; float x, y; int i, n; int obj_x, obj_y, obj_w, obj_h; @@ -239,9 +239,25 @@ _recalc(Evas_Object *obj) evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h); printf("egraph: %d %d %d %d\n", obj_x, obj_y, obj_w, obj_h); - igraph_matrix_init(&coords, eg->vertices_count, 2); - igraph_layout_reingold_tilford(&eg->graph, &coords, IGRAPH_IN, 0, 0); - size_max = igraph_matrix_max(&coords); // XXX do per vertor + //igraph_layout_reingold_tilford(&eg->graph, &coords, IGRAPH_IN, 0, 0); + igraph_layout_kamada_kawai(&eg->graph, &eg->graph_coords, + 1000, eg->vertices_count / 4, + 10, 0.99, + eg->vertices_count ^ 2, 1, + NULL, NULL, NULL, NULL); + + /* +int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, + igraph_integer_t niter, igraph_real_t sigma, + igraph_real_t initemp, igraph_real_t coolexp, + igraph_real_t kkconst, igraph_bool_t use_seed, + const igraph_vector_t *minx, + const igraph_vector_t *maxx, + const igraph_vector_t *miny, + const igraph_vector_t *maxy); + */ + + size_max = igraph_matrix_max(&eg->graph_coords); // XXX do per vertor if (size_max && obj_w && obj_w > size_max) size_factor = (obj_w / size_max) * 0.8; else @@ -256,8 +272,8 @@ _recalc(Evas_Object *obj) for (i=0; igraph, "id", i); - x = MATRIX(coords, i, 0); - y = MATRIX(coords, i, 1); + x = MATRIX(eg->graph_coords, i, 0); + y = MATRIX(eg->graph_coords, i, 1); printf("%d: %6.3f %6.3f id %d\n", i, x, y, id); x = obj_x + (x * size_factor) / 2 + (obj_w/2); y = obj_y + (y * size_factor) / 2 + (obj_h/2); -- cgit v1.2.3-59-g8ed1b From dffd14a72c18570ea386719bedd01ae897bc7414 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 16:36:11 +0100 Subject: formatting --- egraph.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/egraph.c b/egraph.c index a4912ef..24289b4 100644 --- a/egraph.c +++ b/egraph.c @@ -239,24 +239,20 @@ _recalc(Evas_Object *obj) evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h); printf("egraph: %d %d %d %d\n", obj_x, obj_y, obj_w, obj_h); - //igraph_layout_reingold_tilford(&eg->graph, &coords, IGRAPH_IN, 0, 0); +/*int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, + igraph_integer_t niter, igraph_real_t sigma, + igraph_real_t initemp, igraph_real_t coolexp, + igraph_real_t kkconst, igraph_bool_t use_seed, + const igraph_vector_t *minx, + const igraph_vector_t *maxx, + const igraph_vector_t *miny, + const igraph_vector_t *maxy); */ igraph_layout_kamada_kawai(&eg->graph, &eg->graph_coords, 1000, eg->vertices_count / 4, 10, 0.99, eg->vertices_count ^ 2, 1, NULL, NULL, NULL, NULL); - /* -int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, - igraph_integer_t niter, igraph_real_t sigma, - igraph_real_t initemp, igraph_real_t coolexp, - igraph_real_t kkconst, igraph_bool_t use_seed, - const igraph_vector_t *minx, - const igraph_vector_t *maxx, - const igraph_vector_t *miny, - const igraph_vector_t *maxy); - */ - size_max = igraph_matrix_max(&eg->graph_coords); // XXX do per vertor if (size_max && obj_w && obj_w > size_max) size_factor = (obj_w / size_max) * 0.8; -- cgit v1.2.3-59-g8ed1b From bfa1208489886c5d64da967355e82d4ab4d1c753 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 16:55:26 +0100 Subject: remove extra blank line --- egraph.c | 1 - 1 file changed, 1 deletion(-) diff --git a/egraph.c b/egraph.c index 24289b4..b04cb92 100644 --- a/egraph.c +++ b/egraph.c @@ -281,7 +281,6 @@ _recalc(Evas_Object *obj) if (v->name) { evas_object_move(v->o_text, x+3, y+8); evas_object_show(v->o_text); - } } -- cgit v1.2.3-59-g8ed1b From a1f1a83a34ad0b4be02fdeba60eefae9cce55cbf Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 16:55:48 +0100 Subject: oops typo, fix edge line coordinates --- egraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egraph.c b/egraph.c index b04cb92..27aebf7 100644 --- a/egraph.c +++ b/egraph.c @@ -287,7 +287,7 @@ _recalc(Evas_Object *obj) EINA_LIST_FOREACH(eg->edges, l, e) { evas_object_geometry_get(e->a->o, &x1, &y1, NULL, NULL); evas_object_geometry_get(e->b->o, &x2, &y2, NULL, NULL); - evas_object_line_xy_set(e->o, x1, y1, x1, y2); + evas_object_line_xy_set(e->o, x1, y1, x2, y2); evas_object_show(e->o); } } -- cgit v1.2.3-59-g8ed1b From 38c562dbafd4f8b42ed0d660deb0c0b00f65214b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 16:56:15 +0100 Subject: switch layout to igraph_layout_graphopt --- egraph.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/egraph.c b/egraph.c index 27aebf7..811fb5e 100644 --- a/egraph.c +++ b/egraph.c @@ -239,19 +239,40 @@ _recalc(Evas_Object *obj) evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h); printf("egraph: %d %d %d %d\n", obj_x, obj_y, obj_w, obj_h); -/*int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, - igraph_integer_t niter, igraph_real_t sigma, - igraph_real_t initemp, igraph_real_t coolexp, - igraph_real_t kkconst, igraph_bool_t use_seed, - const igraph_vector_t *minx, - const igraph_vector_t *maxx, - const igraph_vector_t *miny, - const igraph_vector_t *maxy); */ - igraph_layout_kamada_kawai(&eg->graph, &eg->graph_coords, +/* int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, + igraph_integer_t niter, igraph_real_t sigma, + igraph_real_t initemp, igraph_real_t coolexp, + igraph_real_t kkconst, igraph_bool_t use_seed, + const igraph_vector_t *minx, + const igraph_vector_t *maxx, + const igraph_vector_t *miny, + const igraph_vector_t *maxy); */ +/* igraph_layout_kamada_kawai(&eg->graph, &eg->graph_coords, 1000, eg->vertices_count / 4, 10, 0.99, eg->vertices_count ^ 2, 1, - NULL, NULL, NULL, NULL); + NULL, NULL, NULL, NULL);*/ +/* int igraph_layout_graphopt(const igraph_t *graph, igraph_matrix_t *res, + igraph_integer_t niter, + igraph_real_t node_charge, igraph_real_t node_mass, + igraph_real_t spring_length, + igraph_real_t spring_constant, + igraph_real_t max_sa_movement, + igraph_bool_t use_seed); */ +/* igraph_layout_graphopt(&eg->graph, &eg->graph_coords, + 1000, + 0.001, 10, + 0, + 1, + 5, + 1); */ + igraph_layout_graphopt(&eg->graph, &eg->graph_coords, + 1000, + 0.001, 10, + 0, + 1, + 5, + 1); size_max = igraph_matrix_max(&eg->graph_coords); // XXX do per vertor if (size_max && obj_w && obj_w > size_max) -- cgit v1.2.3-59-g8ed1b From b1fcbe9f0ecfe25c30fc165f3ad53252ba37dc62 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 18:42:22 +0100 Subject: fix seeding of graph layout and intoduce DEBUG define --- egraph.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/egraph.c b/egraph.c index 811fb5e..51171e5 100644 --- a/egraph.c +++ b/egraph.c @@ -16,6 +16,8 @@ EVAS_SMART_SUBCLASS_NEW("Egraph", _egraph, Evas_Smart_Class, Evas_Smart_Class, evas_object_smart_clipped_class_get, _smart_callbacks); +#define DEBUG 1 + static void _egraph_smart_set_user(Evas_Smart_Class *sc) { @@ -142,6 +144,8 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) EGRAPH_DATA_GET(obj, eg); Egraph_Vertice *v; Evas_Object *vobj, *text; + //igraph_vector_t vector; + int ranx, rany; v = malloc(sizeof(Egraph_Vertice)); if (!v) @@ -158,13 +162,21 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) eg->vertices[v->id] = v; igraph_add_vertices(&eg->graph, 1, 0); + igraph_matrix_add_rows(&eg->graph_coords, 1); + ranx = random() % 200; + rany = random() % 200; + igraph_matrix_set(&eg->graph_coords, eg->vertices_count, 0, ranx); + igraph_matrix_set(&eg->graph_coords, eg->vertices_count, 1, rany); + //igraph_vector_init(&vector, 2); + //igraph_vector_fill(&vector, 0); + //igraph_matrix_set_row(&eg->graph_coords, &vector, 0); v->vertice_id = eg->vertices_count; SETVAN(&eg->graph, "id", eg->vertices_count, v->id); eg->vertices_count++; vobj = evas_object_rectangle_add(eg->evas); evas_object_smart_member_add(vobj, obj); - evas_object_color_set(vobj, 255, 255, 255, 255); + evas_object_color_set(vobj, 0, 0, 255, 255); evas_object_resize(vobj, 10, 10); v->o = vobj; if (name) { @@ -237,7 +249,8 @@ _recalc(Evas_Object *obj) int size_factor; evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h); - printf("egraph: %d %d %d %d\n", obj_x, obj_y, obj_w, obj_h); + if (DEBUG) + printf("egraph: %d %d %d %d\n", obj_x, obj_y, obj_w, obj_h); /* int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, igraph_integer_t niter, igraph_real_t sigma, @@ -267,34 +280,38 @@ _recalc(Evas_Object *obj) 5, 1); */ igraph_layout_graphopt(&eg->graph, &eg->graph_coords, - 1000, - 0.001, 10, + 50, + 0.003, 10, 0, 1, - 5, + 10, 1); - size_max = igraph_matrix_max(&eg->graph_coords); // XXX do per vertor - if (size_max && obj_w && obj_w > size_max) + // XXX do real calculations for scaling + size_max = igraph_matrix_max(&eg->graph_coords); // XXX do per vector + if (size_max > 0 && obj_w > 0 && obj_w > size_max) size_factor = (obj_w / size_max) * 0.8; else size_factor = 1; + size_factor = 1; // XXX DEBUG n = igraph_vcount(&eg->graph); if (n != eg->vertices_count) err(1, "err: n (%d) != vertices_count (%d)\n", n, eg->vertices_count); - printf("[-] _recalc\n"); + if (DEBUG) + printf("[-] _recalc\n"); for (i=0; igraph, "id", i); x = MATRIX(eg->graph_coords, i, 0); y = MATRIX(eg->graph_coords, i, 1); - printf("%d: %6.3f %6.3f id %d\n", i, x, y, id); + // XXX use igraph_matrix_scale(); + //printf("%d: %6.3f %6.3f id %d\n", i, x, y, id); x = obj_x + (x * size_factor) / 2 + (obj_w/2); y = obj_y + (y * size_factor) / 2 + (obj_h/2); - printf(" inobj: %6.3f %6.3f id %d\n", x, y, id); + //printf(" inobj: %6.3f %6.3f id %d\n", x, y, id); v = eg->vertices[id]; evas_object_move(v->o, x, y); -- cgit v1.2.3-59-g8ed1b From b67c9c5176d3f98082172aa2e7f51c9817ac8ee7 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 18:42:59 +0100 Subject: add an interactive app in examples/ --- examples/interactive.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 examples/interactive.c diff --git a/examples/interactive.c b/examples/interactive.c new file mode 100644 index 0000000..fcbd636 --- /dev/null +++ b/examples/interactive.c @@ -0,0 +1,113 @@ +#include + +#include +#include + +Evas_Object *_mainwin, *_egraph; +Eina_List *_vertice_list = NULL; + +static void +_cb_add_edge(void *data, Evas_Object *obj, void *event_info) +{ + Egraph_Vertice *a, *b; + int ran, count; + + count = eina_list_count(_vertice_list); + if (count == 0) { + a = egraph_vertice_add(_egraph, "first", NULL); + _vertice_list = eina_list_append(_vertice_list, a); + } else { + ran = random() % count; + a = eina_list_nth(_vertice_list, ran); + } + b = egraph_vertice_add(_egraph, "node", NULL); + _vertice_list = eina_list_append(_vertice_list, b); + + //printf("edge between vertice %d with %d\n", a->id, b->id); + egraph_edge_add(_egraph, a, b, NULL); +} + +static void +_cb_add_50edges(void *data, Evas_Object *obj, void *event_info) +{ + int i; + + for (i=0; i<50; i++) + _cb_add_edge(data, obj, event_info); +} + +static void +_cb_on_done(void *data, Evas_Object *obj, void *event_info) +{ + elm_exit(); +} + +EAPI_MAIN int +elm_main(int argc, char **argv) +{ + Evas_Object *win, *bg, *panes, *panes_h, *box, *bt, *egraph; + Evas *evas; + Ecore_Timer *timer_libevent; + struct gg_client *ggcli; + int retval = -1; + + win = elm_win_add(NULL, "panes", ELM_WIN_BASIC); + evas = evas_object_evas_get(win); + elm_win_title_set(win, "Glouglou Network Mapper"); + evas_object_smart_callback_add(win, "delete,request", _cb_on_done, NULL); + + bg = elm_bg_add(win); + elm_win_resize_object_add(win, bg); + evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_show(bg); + + panes = elm_panes_add(win); + elm_win_resize_object_add(win, panes); + evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(panes, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(panes); + + box = elm_box_add(win); + elm_box_horizontal_set(box, EINA_FALSE); + evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0); + //elm_box_pack_end(box, box); + evas_object_show(box); + elm_object_part_content_set(panes, "left", box); + + bt = elm_button_add(win); + elm_object_text_set(bt, "Add random edge"); + //evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + //evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_box_pack_end(box, bt); + evas_object_show(bt); + evas_object_smart_callback_add(bt, "clicked", _cb_add_edge, bt); + + bt = elm_button_add(win); + elm_object_text_set(bt, "Add 50 random edges"); + elm_box_pack_end(box, bt); + evas_object_show(bt); + evas_object_smart_callback_add(bt, "clicked", _cb_add_50edges, bt); + + egraph = egraph_new(evas, 1); + if (!egraph) + goto quit; + evas_object_size_hint_weight_set(egraph, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(egraph, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(egraph); + elm_object_part_content_set(panes, "right", egraph); + + evas_object_resize(win, 800, 400); + evas_object_show(win); + evas_object_show(win); + + _egraph = egraph; + _mainwin = win; + + elm_run(); + retval = 0; + +quit: + elm_shutdown(); + return retval; +} +ELM_MAIN() -- cgit v1.2.3-59-g8ed1b From d0ecb0fa800c0494a5d99a1865aa9c3d18131baa Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 18:52:54 +0100 Subject: split repositionning of elements in _reposition() function. use _reposition in _smart_move() and _smart_resize() --- egraph.c | 58 ++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/egraph.c b/egraph.c index 51171e5..4f8695b 100644 --- a/egraph.c +++ b/egraph.c @@ -2,11 +2,13 @@ #include "Egraph.h" -static void _recalc(Evas_Object *obj); static void _smart_add(Evas_Object *obj); static void _smart_del(Evas_Object *obj); +static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y); static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); static void _smart_calculate(Evas_Object *obj); +static void _recalc(Evas_Object *obj); +static void _reposition(Evas_Object *obj); static const Evas_Smart_Cb_Description _smart_callbacks[] = {{NULL, NULL}}; #define EGRAPH_DATA_GET(o, ptr) \ @@ -24,6 +26,7 @@ _egraph_smart_set_user(Evas_Smart_Class *sc) /* specializing these two */ sc->add = _smart_add; sc->del = _smart_del; + sc->move = _smart_move; /* clipped smart object has no hook on resizes or calculations */ sc->resize = _smart_resize; sc->calculate = _smart_calculate; @@ -48,11 +51,20 @@ _smart_del(Evas_Object *obj) _egraph_parent_sc->del(obj); } +static void +_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y) +{ + _reposition(obj); + _egraph_parent_sc->move(obj, x, y); +} + static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h) { + _reposition(obj); } +// XXX what is that for ? static void _smart_calculate(Evas_Object *obj) { @@ -113,6 +125,7 @@ egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, e->data = data; eg->edges = eina_list_append(eg->edges, e); _recalc(obj); + _reposition(obj); return e; err: @@ -136,6 +149,7 @@ egraph_edge_del(Evas_Object *obj, Egraph_Edge *e) eg->edges = eina_list_remove(eg->edges, e); free(e); _recalc(obj); + _reposition(obj); } Egraph_Vertice * @@ -192,6 +206,7 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) v->data = data; _recalc(obj); + _reposition(obj); return v; err: @@ -219,6 +234,7 @@ egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v) eg->vertices_freeids[eg->vertices_count] = v->id; free(v); _recalc(obj); + _reposition(obj); } int @@ -237,20 +253,9 @@ static void _recalc(Evas_Object *obj) { EGRAPH_DATA_GET(obj, eg); - Egraph_Vertice *v; - Egraph_Edge *e; - Eina_List *l; - float x, y; - int i, n; - int obj_x, obj_y, obj_w, obj_h; - int x1, x2, y1, y2; - u_int32_t id; - int size_max; - int size_factor; - evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h); if (DEBUG) - printf("egraph: %d %d %d %d\n", obj_x, obj_y, obj_w, obj_h); + printf("[-] _recalc\n"); /* int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, igraph_integer_t niter, igraph_real_t sigma, @@ -287,6 +292,30 @@ _recalc(Evas_Object *obj) 10, 1); +} + +static void +_reposition(Evas_Object *obj) +{ + EGRAPH_DATA_GET(obj, eg); + Egraph_Vertice *v; + Egraph_Edge *e; + Eina_List *l; + float x, y; + int i, n; + int obj_x, obj_y, obj_w, obj_h; + int x1, x2, y1, y2; + u_int32_t id; + int size_max; + int size_factor; + + if (DEBUG) + printf("[-] _reposition\n"); + + evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h); + if (DEBUG) + printf("egraph: %d %d %d %d\n", obj_x, obj_y, obj_w, obj_h); + // XXX do real calculations for scaling size_max = igraph_matrix_max(&eg->graph_coords); // XXX do per vector if (size_max > 0 && obj_w > 0 && obj_w > size_max) @@ -300,9 +329,6 @@ _recalc(Evas_Object *obj) if (n != eg->vertices_count) err(1, "err: n (%d) != vertices_count (%d)\n", n, eg->vertices_count); - if (DEBUG) - printf("[-] _recalc\n"); - for (i=0; igraph, "id", i); x = MATRIX(eg->graph_coords, i, 0); -- cgit v1.2.3-59-g8ed1b From c465cfa69dd9b301753306f6b038d31a5fef9108 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 19:32:33 +0100 Subject: improve app layout --- examples/interactive.c | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/examples/interactive.c b/examples/interactive.c index fcbd636..e615ba0 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -45,7 +45,7 @@ _cb_on_done(void *data, Evas_Object *obj, void *event_info) EAPI_MAIN int elm_main(int argc, char **argv) { - Evas_Object *win, *bg, *panes, *panes_h, *box, *bt, *egraph; + Evas_Object *win, *bg, *bx, *panes, *tb, *egraph; Evas *evas; Ecore_Timer *timer_libevent; struct gg_client *ggcli; @@ -61,32 +61,31 @@ elm_main(int argc, char **argv) evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_show(bg); + bx = elm_box_add(win); + evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, bx); + evas_object_show(bx); + panes = elm_panes_add(win); - elm_win_resize_object_add(win, panes); evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(panes, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_panes_content_left_size_set(panes, 0.1); evas_object_show(panes); - box = elm_box_add(win); - elm_box_horizontal_set(box, EINA_FALSE); - evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, 0.0); - //elm_box_pack_end(box, box); - evas_object_show(box); - elm_object_part_content_set(panes, "left", box); - - bt = elm_button_add(win); - elm_object_text_set(bt, "Add random edge"); - //evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - //evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_box_pack_end(box, bt); - evas_object_show(bt); - evas_object_smart_callback_add(bt, "clicked", _cb_add_edge, bt); - - bt = elm_button_add(win); - elm_object_text_set(bt, "Add 50 random edges"); - elm_box_pack_end(box, bt); - evas_object_show(bt); - evas_object_smart_callback_add(bt, "clicked", _cb_add_50edges, bt); + tb = elm_toolbar_add(win); + elm_toolbar_horizontal_set(tb, EINA_FALSE); + elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_MENU); + elm_toolbar_select_mode_set(tb, ELM_OBJECT_SELECT_MODE_NONE); + evas_object_size_hint_weight_set(tb, 0.0, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(tb); + elm_toolbar_item_append(tb, "object-rotate-right", "Add 1 edge", + _cb_add_edge, NULL); + elm_toolbar_item_append(tb, "object-rotate-right", "Add 50 edges", + _cb_add_50edges, NULL); + elm_toolbar_item_append(tb, "exit", "Quit", + _cb_on_done, NULL); + elm_object_part_content_set(panes, "left", tb); egraph = egraph_new(evas, 1); if (!egraph) @@ -96,10 +95,10 @@ elm_main(int argc, char **argv) evas_object_show(egraph); elm_object_part_content_set(panes, "right", egraph); - evas_object_resize(win, 800, 400); - evas_object_show(win); - evas_object_show(win); + elm_box_pack_end(bx, panes); + evas_object_resize(win, 650, 500); + evas_object_show(win); _egraph = egraph; _mainwin = win; -- cgit v1.2.3-59-g8ed1b From 71848504539e95c68b7486fdb72a59c8db0002d5 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 20:35:42 +0100 Subject: remove commented printf --- examples/interactive.c | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/interactive.c b/examples/interactive.c index e615ba0..203b520 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -23,7 +23,6 @@ _cb_add_edge(void *data, Evas_Object *obj, void *event_info) b = egraph_vertice_add(_egraph, "node", NULL); _vertice_list = eina_list_append(_vertice_list, b); - //printf("edge between vertice %d with %d\n", a->id, b->id); egraph_edge_add(_egraph, a, b, NULL); } -- cgit v1.2.3-59-g8ed1b From f8fb5dc60d09a61c268b1a1b947f21a6c7648455 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 20:35:54 +0100 Subject: fix vertice / edge positionning --- egraph.c | 96 ++++++++++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 33 deletions(-) diff --git a/egraph.c b/egraph.c index 4f8695b..9670f47 100644 --- a/egraph.c +++ b/egraph.c @@ -2,6 +2,15 @@ #include "Egraph.h" +#define DEBUG 0 + +#define VERTICE_OBJ_W 10 +#define VERTICE_OBJ_H 10 +#define VERTICE_TEXT_W 20 +#define VERTICE_TEXT_H 10 +#define VERTICE_W (VERTICE_OBJ_W + VERTICE_TEXT_W) +#define VERTICE_H (VERTICE_OBJ_H + VERTICE_TEXT_H) + static void _smart_add(Evas_Object *obj); static void _smart_del(Evas_Object *obj); static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y); @@ -9,6 +18,9 @@ static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); static void _smart_calculate(Evas_Object *obj); static void _recalc(Evas_Object *obj); static void _reposition(Evas_Object *obj); +static void _matrix_minmax_2v(const igraph_matrix_t *m, int row_count, + float *c1min, float *c1max, + float *c2min, float *c2max); static const Evas_Smart_Cb_Description _smart_callbacks[] = {{NULL, NULL}}; #define EGRAPH_DATA_GET(o, ptr) \ @@ -18,8 +30,6 @@ EVAS_SMART_SUBCLASS_NEW("Egraph", _egraph, Evas_Smart_Class, Evas_Smart_Class, evas_object_smart_clipped_class_get, _smart_callbacks); -#define DEBUG 1 - static void _egraph_smart_set_user(Evas_Smart_Class *sc) { @@ -191,14 +201,14 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) vobj = evas_object_rectangle_add(eg->evas); evas_object_smart_member_add(vobj, obj); evas_object_color_set(vobj, 0, 0, 255, 255); - evas_object_resize(vobj, 10, 10); + evas_object_resize(vobj, VERTICE_OBJ_W, VERTICE_OBJ_H); v->o = vobj; if (name) { text = evas_object_text_add(eg->evas); evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); evas_object_color_set(text, 0, 255, 0, 255); - evas_object_text_font_set(text, "Vera-Bold", 10); - evas_object_resize(text, 30, 30); // XXX + evas_object_text_font_set(text, "Vera-Bold", VERTICE_TEXT_H); + //evas_object_resize(text, 30, 30); // XXX evas_object_text_text_set(text, name); evas_object_smart_member_add(text, obj); v->o_text = text; @@ -301,43 +311,38 @@ _reposition(Evas_Object *obj) Egraph_Vertice *v; Egraph_Edge *e; Eina_List *l; + u_int32_t id; + float gw_min, gw_max, gh_min, gh_max, factor_w, factor_h; float x, y; - int i, n; int obj_x, obj_y, obj_w, obj_h; int x1, x2, y1, y2; - u_int32_t id; - int size_max; - int size_factor; + int vcur; if (DEBUG) printf("[-] _reposition\n"); + if (eg->vertices_count == 0) + return; evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h); + _matrix_minmax_2v(&eg->graph_coords, eg->vertices_count, + &gw_min, &gw_max, &gh_min, &gh_max); if (DEBUG) - printf("egraph: %d %d %d %d\n", obj_x, obj_y, obj_w, obj_h); - - // XXX do real calculations for scaling - size_max = igraph_matrix_max(&eg->graph_coords); // XXX do per vector - if (size_max > 0 && obj_w > 0 && obj_w > size_max) - size_factor = (obj_w / size_max) * 0.8; - else - size_factor = 1; - size_factor = 1; - - // XXX DEBUG - n = igraph_vcount(&eg->graph); - if (n != eg->vertices_count) - err(1, "err: n (%d) != vertices_count (%d)\n", n, eg->vertices_count); - - for (i=0; igraph, "id", i); - x = MATRIX(eg->graph_coords, i, 0); - y = MATRIX(eg->graph_coords, i, 1); - // XXX use igraph_matrix_scale(); - //printf("%d: %6.3f %6.3f id %d\n", i, x, y, id); - x = obj_x + (x * size_factor) / 2 + (obj_w/2); - y = obj_y + (y * size_factor) / 2 + (obj_h/2); - //printf(" inobj: %6.3f %6.3f id %d\n", x, y, id); + printf("gw_min %6.3f gw_max %6.3f gh_min %6.3f gh_max %6.3f\n", + gw_min, gw_max, gh_min, gh_max); + factor_w = (obj_w - VERTICE_W) / (gw_max - gw_min); + factor_h = (obj_h - VERTICE_H) / (gh_max - gh_min); + + for (vcur=0; vcurvertices_count; vcur++) { + id = VAN(&eg->graph, "id", vcur); + + x = MATRIX(eg->graph_coords, vcur, 0); + y = MATRIX(eg->graph_coords, vcur, 1); + if (DEBUG) + printf("%d: %6.3f %6.3f id %d\n", vcur, x, y, id); + x = obj_x + ((x - gw_min) * factor_w); + y = obj_y + ((y - gh_min) * factor_h); + if (DEBUG) + printf(" inobj: %6.3f %6.3f\n", x, y); v = eg->vertices[id]; evas_object_move(v->o, x, y); @@ -355,3 +360,28 @@ _reposition(Evas_Object *obj) evas_object_show(e->o); } } + +/** + * Compute minimum and maximum of a matrices of 2 colum vectors + * + * @note igraph is crazy in the coconut + */ +static void +_matrix_minmax_2v(const igraph_matrix_t *m, int row_count, + float *c1min, float *c1max, float *c2min, float *c2max) +{ + float val; + int row; + + *c1min=MATRIX(*m, 0, 0); *c1max=MATRIX(*m, 0, 0); + *c2min=MATRIX(*m, 0, 1); *c2max=MATRIX(*m, 0, 1); + + for (row=1; row *c1max) *c1max = val; + val = MATRIX(*m, row, 1); + if (val < *c2min) *c2min = val; + else if (val > *c2max) *c2max = val; + } +} -- cgit v1.2.3-59-g8ed1b From 272bc4b9fdfa0d2ca1acb864de35b39eb5846e64 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 21:07:13 +0100 Subject: XXX ++ --- egraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egraph.c b/egraph.c index 9670f47..8c33ed4 100644 --- a/egraph.c +++ b/egraph.c @@ -6,7 +6,7 @@ #define VERTICE_OBJ_W 10 #define VERTICE_OBJ_H 10 -#define VERTICE_TEXT_W 20 +#define VERTICE_TEXT_W 20 // XXX dynamicaly get the max on each new name #define VERTICE_TEXT_H 10 #define VERTICE_W (VERTICE_OBJ_W + VERTICE_TEXT_W) #define VERTICE_H (VERTICE_OBJ_H + VERTICE_TEXT_H) -- cgit v1.2.3-59-g8ed1b From 4f38f827d37394e09c7e3b900593b725db67ff10 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 21:07:23 +0100 Subject: expand graph coords matrix just before the rendering. cleaner, and will be usefull soon. --- Egraph.h | 2 ++ egraph.c | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/Egraph.h b/Egraph.h index 5f3063e..a3c813b 100644 --- a/Egraph.h +++ b/Egraph.h @@ -1,5 +1,6 @@ #include #include +#include #include #define EGRAPH_VERTICES_MAX 16384 /* cannot be more that u_int32_t */ @@ -17,6 +18,7 @@ struct Egraph { igraph_matrix_t graph_coords; Egraph_Vertice *vertices[EGRAPH_VERTICES_MAX]; int vertices_count; + int vertices_added; u_int32_t vertices_freeids[EGRAPH_VERTICES_MAX]; Eina_List *edges; char *layout; // XXX diff --git a/egraph.c b/egraph.c index 8c33ed4..25708c4 100644 --- a/egraph.c +++ b/egraph.c @@ -168,8 +168,6 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) EGRAPH_DATA_GET(obj, eg); Egraph_Vertice *v; Evas_Object *vobj, *text; - //igraph_vector_t vector; - int ranx, rany; v = malloc(sizeof(Egraph_Vertice)); if (!v) @@ -186,14 +184,7 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) eg->vertices[v->id] = v; igraph_add_vertices(&eg->graph, 1, 0); - igraph_matrix_add_rows(&eg->graph_coords, 1); - ranx = random() % 200; - rany = random() % 200; - igraph_matrix_set(&eg->graph_coords, eg->vertices_count, 0, ranx); - igraph_matrix_set(&eg->graph_coords, eg->vertices_count, 1, rany); - //igraph_vector_init(&vector, 2); - //igraph_vector_fill(&vector, 0); - //igraph_matrix_set_row(&eg->graph_coords, &vector, 0); + eg->vertices_added++; v->vertice_id = eg->vertices_count; SETVAN(&eg->graph, "id", eg->vertices_count, v->id); eg->vertices_count++; @@ -263,6 +254,18 @@ static void _recalc(Evas_Object *obj) { EGRAPH_DATA_GET(obj, eg); + int ranx, rany; + int i, id; + + for (i=0; ivertices_added; i++) { + id = (eg->vertices_count - eg->vertices_added) + i; + igraph_matrix_add_rows(&eg->graph_coords, 1); + ranx = random() % 200; + rany = random() % 200; + igraph_matrix_set(&eg->graph_coords, id, 0, ranx); + igraph_matrix_set(&eg->graph_coords, id, 1, rany); + } + eg->vertices_added = 0; if (DEBUG) printf("[-] _recalc\n"); -- cgit v1.2.3-59-g8ed1b From ac73ac5592eaab0b9f72ce784184b63d1131cba9 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 22:00:04 +0100 Subject: do the layouting in a thread, which start is delayed to next ecore event --- Egraph.h | 9 +++++- egraph.c | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 87 insertions(+), 20 deletions(-) diff --git a/Egraph.h b/Egraph.h index a3c813b..63cdf40 100644 --- a/Egraph.h +++ b/Egraph.h @@ -12,16 +12,23 @@ typedef struct Egraph_Vertice Egraph_Vertice; struct Egraph { Evas_Object_Smart_Clipped_Data __clipped_data; + Evas_Object *obj; Evas *evas; igraph_t graph; int graph_directed; - igraph_matrix_t graph_coords; + igraph_matrix_t graph_coords; /* modified by layouting thread */ Egraph_Vertice *vertices[EGRAPH_VERTICES_MAX]; int vertices_count; int vertices_added; u_int32_t vertices_freeids[EGRAPH_VERTICES_MAX]; Eina_List *edges; char *layout; // XXX + struct { + Ecore_Thread *thread; + int running; + igraph_t graph; + int todo; + } layouting; }; struct Egraph_Vertice { diff --git a/egraph.c b/egraph.c index 25708c4..737e9dc 100644 --- a/egraph.c +++ b/egraph.c @@ -16,8 +16,12 @@ static void _smart_del(Evas_Object *obj); static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y); static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); static void _smart_calculate(Evas_Object *obj); -static void _recalc(Evas_Object *obj); -static void _reposition(Evas_Object *obj); +static void _layouting_schedule(Egraph *eg); +static Eina_Bool _cb_layouting_start(void *data); +static void _cb_layouting_run(void *data, Ecore_Thread *thread); +static void _cb_layouting_end(void *data, Ecore_Thread *thread); +static void _cb_layouting_cancel(void *data, Ecore_Thread *thread); +static void _reposition(Egraph *eg); static void _matrix_minmax_2v(const igraph_matrix_t *m, int row_count, float *c1min, float *c1max, float *c2min, float *c2max); @@ -58,20 +62,28 @@ _smart_del(Evas_Object *obj) EGRAPH_DATA_GET(obj, eg); igraph_destroy(&eg->graph); + if (eg->layouting.running == 2) + ecore_thread_cancel(eg->layouting.thread); + _egraph_parent_sc->del(obj); } static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y) { - _reposition(obj); + EGRAPH_DATA_GET(obj, eg); + + _reposition(eg); + _egraph_parent_sc->move(obj, x, y); } static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h) { - _reposition(obj); + EGRAPH_DATA_GET(obj, eg); + + _reposition(eg); } // XXX what is that for ? @@ -92,6 +104,7 @@ egraph_new(Evas *evas, int directed) obj = evas_object_smart_add(evas, _egraph_smart_class_new()); eg = evas_object_smart_data_get(obj); if (!eg) goto err; + eg->obj = obj; /* needed for igraph attribute handling */ igraph_i_set_attribute_table(&igraph_cattribute_table); @@ -134,8 +147,7 @@ egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, e->data = data; eg->edges = eina_list_append(eg->edges, e); - _recalc(obj); - _reposition(obj); + _layouting_schedule(eg); return e; err: @@ -158,8 +170,7 @@ egraph_edge_del(Evas_Object *obj, Egraph_Edge *e) eg->edges = eina_list_remove(eg->edges, e); free(e); - _recalc(obj); - _reposition(obj); + _layouting_schedule(eg); } Egraph_Vertice * @@ -206,8 +217,7 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) } v->data = data; - _recalc(obj); - _reposition(obj); + _layouting_schedule(eg); return v; err: @@ -234,8 +244,7 @@ egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v) eg->vertices_count--; eg->vertices_freeids[eg->vertices_count] = v->id; free(v); - _recalc(obj); - _reposition(obj); + _layouting_schedule(eg); } int @@ -251,12 +260,26 @@ egraph_layout_set(Evas_Object *obj, const char *layout) } static void -_recalc(Evas_Object *obj) +_layouting_schedule(Egraph *eg) { - EGRAPH_DATA_GET(obj, eg); + if (eg->layouting.running > 0) { + eg->layouting.todo = 1; + return; + } + + eg->layouting.running = 1; + ecore_timer_add(0.0, _cb_layouting_start, eg); /* delayed start */ +} + +static Eina_Bool +_cb_layouting_start(void *data) +{ + Egraph *eg; int ranx, rany; int i, id; + eg = data; + for (i=0; ivertices_added; i++) { id = (eg->vertices_count - eg->vertices_added) + i; igraph_matrix_add_rows(&eg->graph_coords, 1); @@ -266,9 +289,24 @@ _recalc(Evas_Object *obj) igraph_matrix_set(&eg->graph_coords, id, 1, rany); } eg->vertices_added = 0; + igraph_copy(&eg->layouting.graph, &eg->graph); + + eg->layouting.running = 2; + eg->layouting.thread = ecore_thread_run(_cb_layouting_run, _cb_layouting_end, + _cb_layouting_cancel, eg); + + return EINA_FALSE; /* no repeat */ +} + +void +_cb_layouting_run(void *data, Ecore_Thread *thread) +{ + Egraph *eg; + + eg = data; if (DEBUG) - printf("[-] _recalc\n"); + printf("[-] _cb_layouting_run\n"); /* int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, igraph_integer_t niter, igraph_real_t sigma, @@ -297,20 +335,42 @@ _recalc(Evas_Object *obj) 1, 5, 1); */ - igraph_layout_graphopt(&eg->graph, &eg->graph_coords, + igraph_layout_graphopt(&eg->layouting.graph, &eg->graph_coords, 50, 0.003, 10, 0, 1, 10, 1); +} + +void +_cb_layouting_end(void *data, Ecore_Thread *thread) +{ + Egraph *eg; + eg = data; + eg->layouting.running = 0; + _reposition(eg); + if (eg->layouting.todo) { + _layouting_schedule(eg); + eg->layouting.todo = 0; + } +} + +void +_cb_layouting_cancel(void *data, Ecore_Thread *thread) +{ + Egraph *eg; + + eg = data; + eg->layouting.running = 0; + eg->layouting.todo = 0; } static void -_reposition(Evas_Object *obj) +_reposition(Egraph *eg) { - EGRAPH_DATA_GET(obj, eg); Egraph_Vertice *v; Egraph_Edge *e; Eina_List *l; @@ -326,7 +386,7 @@ _reposition(Evas_Object *obj) if (eg->vertices_count == 0) return; - evas_object_geometry_get(obj, &obj_x, &obj_y, &obj_w, &obj_h); + evas_object_geometry_get(eg->obj, &obj_x, &obj_y, &obj_w, &obj_h); _matrix_minmax_2v(&eg->graph_coords, eg->vertices_count, &gw_min, &gw_max, &gh_min, &gh_max); if (DEBUG) -- cgit v1.2.3-59-g8ed1b From decd098db69b09889af1d4e717e2dd56685a20bd Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 22:07:06 +0100 Subject: fix a bug where we did double layouting when adding any vertice / edge --- egraph.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/egraph.c b/egraph.c index 737e9dc..6e1e8bf 100644 --- a/egraph.c +++ b/egraph.c @@ -280,6 +280,8 @@ _cb_layouting_start(void *data) eg = data; + eg->layouting.todo = 0; + for (i=0; ivertices_added; i++) { id = (eg->vertices_count - eg->vertices_added) + i; igraph_matrix_add_rows(&eg->graph_coords, 1); -- cgit v1.2.3-59-g8ed1b From 0712dc12d5af846fe74bc4c8d5ff5745339e4739 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 22:07:41 +0100 Subject: add printf to mesure layouting thread time --- egraph.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index 6e1e8bf..9b19b7f 100644 --- a/egraph.c +++ b/egraph.c @@ -308,7 +308,7 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) eg = data; if (DEBUG) - printf("[-] _cb_layouting_run\n"); + printf("[-] _cb_layouting_run begin\n"); /* int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, igraph_integer_t niter, igraph_real_t sigma, @@ -338,12 +338,14 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) 5, 1); */ igraph_layout_graphopt(&eg->layouting.graph, &eg->graph_coords, - 50, + 1000, 0.003, 10, 0, 1, 10, 1); + if (DEBUG) + printf("[-] _cb_layouting_run end\n"); } void -- cgit v1.2.3-59-g8ed1b From 8452fb3f563d0744a18241d4203749801a578645 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 22:10:23 +0100 Subject: use default value for max_sa_movement in igraph_layout_graphopt() --- egraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egraph.c b/egraph.c index 9b19b7f..3e1d01e 100644 --- a/egraph.c +++ b/egraph.c @@ -342,7 +342,7 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) 0.003, 10, 0, 1, - 10, + 5, 1); if (DEBUG) printf("[-] _cb_layouting_run end\n"); -- cgit v1.2.3-59-g8ed1b From eeeb84a6de1b1ef6af6dcb55b7885515f81a11b5 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 22:15:50 +0100 Subject: TODO section ++ --- README.txt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.txt b/README.txt index b957ea3..fefcc30 100644 --- a/README.txt +++ b/README.txt @@ -19,3 +19,17 @@ Installation make sudo make install + +TODO +==== + +* possible future API: no edges no vertices for the user +struct Egraph_Vertice { + const char *name; + int vertice_id; + Evas_Object *o; + void *data; +} +egraph_vertice_add(Egraph *eg, const char *name, void *data); +egraph_edge_add(Egraph *eg, + const char *a, const char *b, void *data); -- cgit v1.2.3-59-g8ed1b From 64ee82c7ecb9be91094140b293e2c83ea5ef5f09 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 6 Dec 2012 22:15:56 +0100 Subject: cleanup old code and comments, no functionnal change --- Egraph.h | 13 ------------- egraph.c | 9 --------- 2 files changed, 22 deletions(-) diff --git a/Egraph.h b/Egraph.h index 63cdf40..8921589 100644 --- a/Egraph.h +++ b/Egraph.h @@ -67,7 +67,6 @@ int egraph_layout_set(Evas_Object *obj, const char *layout); * @param b Second vertice * @param data The pointer to attach * @return The new Egraph_Egde object - * @todo XXX make a function that creates the missing vertices to avoid dual recalc */ Egraph_Edge *egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, void *data); @@ -100,15 +99,3 @@ Egraph_Vertice *egraph_vertice_add(Evas_Object *obj, */ void egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v); -/* XXX possible future API: no edges no vertices for the user */ -/* -struct Egraph_Vertice { - const char *name; - int vertice_id; - Evas_Object *o; - void *data; -} -egraph_vertice_add(Egraph *eg, const char *name, void *data); -egraph_edge_add(Egraph *eg, - const char *a, const char *b, void *data); -*/ diff --git a/egraph.c b/egraph.c index 3e1d01e..0959255 100644 --- a/egraph.c +++ b/egraph.c @@ -15,7 +15,6 @@ static void _smart_add(Evas_Object *obj); static void _smart_del(Evas_Object *obj); static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y); static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); -static void _smart_calculate(Evas_Object *obj); static void _layouting_schedule(Egraph *eg); static Eina_Bool _cb_layouting_start(void *data); static void _cb_layouting_run(void *data, Ecore_Thread *thread); @@ -43,7 +42,6 @@ _egraph_smart_set_user(Evas_Smart_Class *sc) sc->move = _smart_move; /* clipped smart object has no hook on resizes or calculations */ sc->resize = _smart_resize; - sc->calculate = _smart_calculate; } static void @@ -86,12 +84,6 @@ _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h) _reposition(eg); } -// XXX what is that for ? -static void -_smart_calculate(Evas_Object *obj) -{ -} - Evas_Object * egraph_new(Evas *evas, int directed) { @@ -210,7 +202,6 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); evas_object_color_set(text, 0, 255, 0, 255); evas_object_text_font_set(text, "Vera-Bold", VERTICE_TEXT_H); - //evas_object_resize(text, 30, 30); // XXX evas_object_text_text_set(text, name); evas_object_smart_member_add(text, obj); v->o_text = text; -- cgit v1.2.3-59-g8ed1b From 8b9ccf9b7eefde25fd665e18584ed0c5520842cd Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 7 Dec 2012 16:16:33 +0100 Subject: add button to add 500 edges --- examples/interactive.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/examples/interactive.c b/examples/interactive.c index 203b520..3019c72 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -35,6 +35,15 @@ _cb_add_50edges(void *data, Evas_Object *obj, void *event_info) _cb_add_edge(data, obj, event_info); } +static void +_cb_add_500edges(void *data, Evas_Object *obj, void *event_info) +{ + int i; + + for (i=0; i<500; i++) + _cb_add_edge(data, obj, event_info); +} + static void _cb_on_done(void *data, Evas_Object *obj, void *event_info) { @@ -82,6 +91,8 @@ elm_main(int argc, char **argv) _cb_add_edge, NULL); elm_toolbar_item_append(tb, "object-rotate-right", "Add 50 edges", _cb_add_50edges, NULL); + elm_toolbar_item_append(tb, "object-rotate-right", "Add 500 edges", + _cb_add_500edges, NULL); elm_toolbar_item_append(tb, "exit", "Quit", _cb_on_done, NULL); elm_object_part_content_set(panes, "left", tb); -- cgit v1.2.3-59-g8ed1b From 2b438f288c00cc4c931576c2a03b3042ab671b33 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 7 Dec 2012 16:17:06 +0100 Subject: add algo to handle threaded graph layouting correctly --- README.txt | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/README.txt b/README.txt index fefcc30..23fcb42 100644 --- a/README.txt +++ b/README.txt @@ -23,7 +23,87 @@ sudo make install TODO ==== -* possible future API: no edges no vertices for the user +=== algo to handle threaded graph layouting correctly === + +###### ALGO +_layouting_start(graph-2, coords-2); + +_add/del(structs-3); +_repositionning(graph, structs, coords); + +_layouting_end(coords-2); + +_v2_updtate(structs-2, graph-2, coords-2); + _v2_structs/graph_update(structs-2, graph); + -> structs, graph // real add/del + _coords_copy(coords-2); + -> coords + +_repositionning(graph, structs, coords); + +_v3_update(structs-3); + _v3_structs/graph_update(structs-3, graph-2); + -> structs-2, graph-2 + +###### TIMELINE VERTICE ADD +egraph_vertice_add(); + v->v3-new = 1; + +_v3_update(); + v->v2-new = v->v3-new; + v->v3-new = 0; + _v2_add() + v->id = freeids[]; + v->graph2_vid = graph2_vcount; + graph2_vcount++; + igraph_add_vertices(graph2); + +_layouting_start(); + // end up in coords2 + +_layouting_end(); +_coords_copy(); + // end up in coords + +_v2_update(); + _add() + v->v2-new = 0; + v->graph_vid = graph_vcount; + graph_vcount++; + igraph_add_vertices(graph); + evas_object + +// in structs, graph, coords + +###### TIMELINE VERTICE DEL +egraph_vertice_del(); + v->v3-del = 1; + +_v3_update(); + v->v2-del = v->v3-del; + v->v3-del = 0; + _v2_del() + igraph_delete_vertices(v->graph2_vid); + graph2_vcount--; + +_layouting_start(); + // not in coords2 + +_layouting_end(); +_coords_copy(); + // not in coords + +_v2_update(); + _del(); + igraph_delete_vertices(v->graph_vid); + graph_vcount--; + freeids[vcount] = v->id; + free(v); + +// removed from structs, graph, coords + +=== possible future API: no edges no vertices for the user === + struct Egraph_Vertice { const char *name; int vertice_id; @@ -33,3 +113,4 @@ struct Egraph_Vertice { egraph_vertice_add(Egraph *eg, const char *name, void *data); egraph_edge_add(Egraph *eg, const char *a, const char *b, void *data); + -- cgit v1.2.3-59-g8ed1b From c389d53b8c5f4c7a48441f7bded53427e6585ffa Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 7 Dec 2012 20:03:36 +0100 Subject: more on algo to handle threaded graph layouting correctly --- README.txt | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/README.txt b/README.txt index 23fcb42..ff535cd 100644 --- a/README.txt +++ b/README.txt @@ -25,7 +25,7 @@ TODO === algo to handle threaded graph layouting correctly === -###### ALGO +###### GENERAL ALGO _layouting_start(graph-2, coords-2); _add/del(structs-3); @@ -47,13 +47,16 @@ _v3_update(structs-3); ###### TIMELINE VERTICE ADD egraph_vertice_add(); + id = freeids[vertices_count]; + v = vertices[id]; + v->id = id; + vertices_count++; v->v3-new = 1; _v3_update(); v->v2-new = v->v3-new; v->v3-new = 0; _v2_add() - v->id = freeids[]; v->graph2_vid = graph2_vcount; graph2_vcount++; igraph_add_vertices(graph2); @@ -97,11 +100,15 @@ _v2_update(); _del(); igraph_delete_vertices(v->graph_vid); graph_vcount--; - freeids[vcount] = v->id; + freeids[vertices_count] = v->id; + vertices_count--; free(v); // removed from structs, graph, coords +###### TIMELINE VERTICE DEL + + === possible future API: no edges no vertices for the user === struct Egraph_Vertice { -- cgit v1.2.3-59-g8ed1b From 2ddbeddfb11b0a533e7b0d60f73b4a00e903b2b0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 04:34:23 +0100 Subject: work in progress on correct threaded handling WARNING: BROKEN !! it only compiles --- Egraph.h | 50 +++++--- egraph.c | 415 ++++++++++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 355 insertions(+), 110 deletions(-) diff --git a/Egraph.h b/Egraph.h index 8921589..ae53bc5 100644 --- a/Egraph.h +++ b/Egraph.h @@ -10,34 +10,45 @@ typedef struct Egraph Egraph; typedef struct Egraph_Edge Egraph_Edge; typedef struct Egraph_Vertice Egraph_Vertice; +typedef enum { + EGRAPH_LAYOUT_GRAPHOPT = 0, +} Egraph_Layout; + struct Egraph { Evas_Object_Smart_Clipped_Data __clipped_data; Evas_Object *obj; Evas *evas; - igraph_t graph; int graph_directed; - igraph_matrix_t graph_coords; /* modified by layouting thread */ - Egraph_Vertice *vertices[EGRAPH_VERTICES_MAX]; + Egraph_Layout layout; + struct { + Ecore_Thread *thread; + int running; + int todo; + int changes_diff; + } layouting; + Eina_Hash *vertices; int vertices_count; - int vertices_added; u_int32_t vertices_freeids[EGRAPH_VERTICES_MAX]; Eina_List *edges; - char *layout; // XXX - struct { - Ecore_Thread *thread; - int running; - igraph_t graph; - int todo; - } layouting; + igraph_t graph; + int graph_vcount; + igraph_matrix_t coords; + igraph_t graph2; // XXX remove use of graph here, see _repos() + int graph2_vcount; + igraph_matrix_t coords2; }; struct Egraph_Vertice { u_int32_t id; const char *name; - int vertice_id; Evas_Object *o; Evas_Object *o_text; void *data; + int new : 1; + int v2_new : 1; + int v2_del : 1; + int v3_new : 1; + int v3_del : 1; }; struct Egraph_Edge { @@ -45,6 +56,11 @@ struct Egraph_Edge { Egraph_Vertice *b; Evas_Object *o; void *data; + int new : 1; + int v2_new : 1; + int v2_del : 1; + int v3_new : 1; + int v3_del : 1; }; /** @@ -54,10 +70,8 @@ Evas_Object *egraph_new(Evas *evas, int directed); /** * Sets the layout of Egraph - * - * @warning XXX not functionnal */ -int egraph_layout_set(Evas_Object *obj, const char *layout); +void egraph_layout_set(Evas_Object *obj, Egraph_Layout layout); /** * Adds an edge between existing vertices @@ -99,3 +113,9 @@ Egraph_Vertice *egraph_vertice_add(Evas_Object *obj, */ void egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v); +/** + * Update the name of a vertice + */ +void egraph_vertice_rename(Evas_Object *obj, Egraph_Vertice *v, + const char *name); + diff --git a/egraph.c b/egraph.c index 0959255..4726dd5 100644 --- a/egraph.c +++ b/egraph.c @@ -15,11 +15,23 @@ static void _smart_add(Evas_Object *obj); static void _smart_del(Evas_Object *obj); static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y); static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); +static void _edge_v2_add(Egraph *eg, Egraph_Edge *e); +static void _edge_del(Egraph *eg, Egraph_Edge *e); +static void _edge_v2_del(Egraph *eg, Egraph_Edge *e); +static void _edge_del(Egraph *eg, Egraph_Edge *e); +static void _vertice_v2_add(Egraph *eg, Egraph_Vertice *v); +static void _vertice_add(Egraph *eg, Egraph_Vertice *v); +static void _vertice_v2_del(Egraph *eg, Egraph_Vertice *v); +static void _vertice_del(Egraph *eg, Egraph_Vertice *v); +static void _v2_update(Egraph *eg); +static void _v3_update(Egraph *eg); +static void _coords2_copy(Egraph *eg); static void _layouting_schedule(Egraph *eg); static Eina_Bool _cb_layouting_start(void *data); static void _cb_layouting_run(void *data, Ecore_Thread *thread); static void _cb_layouting_end(void *data, Ecore_Thread *thread); static void _cb_layouting_cancel(void *data, Ecore_Thread *thread); +static int _igraph_query_vid(igraph_t *g, int g_len, int id); static void _reposition(Egraph *eg); static void _matrix_minmax_2v(const igraph_matrix_t *m, int row_count, float *c1min, float *c1max, @@ -98,15 +110,21 @@ egraph_new(Evas *evas, int directed) if (!eg) goto err; eg->obj = obj; + eg->graph_directed = directed; + eg->layout = EGRAPH_LAYOUT_GRAPHOPT; + /* needed for igraph attribute handling */ igraph_i_set_attribute_table(&igraph_cattribute_table); - if (igraph_empty(&eg->graph, 0, directed)) - goto err; - igraph_matrix_init(&eg->graph_coords, 0, 2); - eg->graph_directed = directed; + eg->vertices = eina_hash_int32_new(NULL); for (i=0; ivertices_freeids[i] = i; + if (igraph_empty(&eg->graph, 0, directed)) + goto err; + if (igraph_empty(&eg->graph2, 0, directed)) + goto err; + igraph_matrix_init(&eg->coords, 0, 2); + igraph_matrix_init(&eg->coords2, 0, 2); return obj; @@ -116,53 +134,106 @@ err: return NULL; } +void +egraph_layout_set(Evas_Object *obj, Egraph_Layout layout) +{ + EGRAPH_DATA_GET(obj, eg); + + eg->layout = layout; + _layouting_schedule(eg); +} + Egraph_Edge * egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, void *data) { EGRAPH_DATA_GET(obj, eg); - Evas_Object *eobj; Egraph_Edge *e; - e = malloc(sizeof(Egraph_Edge)); + e = calloc(1, sizeof(Egraph_Edge)); if (!e) - goto err;; - + return NULL; + e->v3_new = 1; e->a = a; e->b = b; - igraph_add_edge(&eg->graph, a->vertice_id, b->vertice_id); - - eobj = evas_object_line_add(eg->evas); - evas_object_smart_member_add(eobj, obj); - evas_object_color_set(eobj, 255, 0, 0, 255); - e->o = eobj; - e->data = data; eg->edges = eina_list_append(eg->edges, e); + _layouting_schedule(eg); return e; +} -err: - if (e) - free(e); - return NULL; +static void +_edge_v2_add(Egraph *eg, Egraph_Edge *e) +{ + int a_pos, b_pos; + + e->v2_new = 1; + e->v3_new = 0; + + a_pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, e->a->id); + b_pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, e->b->id); + igraph_add_edge(&eg->graph2, a_pos, b_pos); +} + +static void +_edge_add(Egraph *eg, Egraph_Edge *e) +{ + Evas_Object *eobj; + int a_pos, b_pos; + + e->new = 1; + e->v2_new = 0; + + a_pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, e->a->id); + b_pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, e->b->id); + igraph_add_edge(&eg->graph, a_pos, b_pos); + + eobj = evas_object_line_add(eg->evas); + evas_object_smart_member_add(eobj, eg->obj); + evas_object_color_set(eobj, 255, 0, 0, 255); + e->o = eobj; } void egraph_edge_del(Evas_Object *obj, Egraph_Edge *e) { EGRAPH_DATA_GET(obj, eg); - igraph_es_t es; - igraph_es_pairs_small(&es, eg->graph_directed, - e->a->vertice_id, e->b->vertice_id, -1); + e->v3_del = 1; + _layouting_schedule(eg); +} + +static void +_edge_v2_del(Egraph *eg, Egraph_Edge *e) +{ + igraph_es_t es; + int a_pos, b_pos; + + e->v2_del = 1; + e->v3_del = 0; + + a_pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, e->a->id); + b_pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, e->b->id); + igraph_es_pairs_small(&es, eg->graph_directed, a_pos, b_pos, -1); + igraph_delete_edges(&eg->graph2, es); +} + +static void +_edge_del(Egraph *eg, Egraph_Edge *e) +{ + igraph_es_t es; + int a_pos, b_pos; + + a_pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, e->a->id); + b_pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, e->b->id); + igraph_es_pairs_small(&es, eg->graph_directed, a_pos, b_pos, -1); igraph_delete_edges(&eg->graph, es); evas_object_del(e->o); eg->edges = eina_list_remove(eg->edges, e); free(e); - _layouting_schedule(eg); } Egraph_Vertice * @@ -170,51 +241,61 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) { EGRAPH_DATA_GET(obj, eg); Egraph_Vertice *v; - Evas_Object *vobj, *text; + u_int32_t id; - v = malloc(sizeof(Egraph_Vertice)); + if (eg->vertices_count == EGRAPH_VERTICES_MAX) { + printf("egraph error: maximum number of vertices reached !\n"); + return NULL; + } + v = calloc(1, sizeof(Egraph_Vertice)); if (!v) return NULL; - if (eg->vertices_count == EGRAPH_VERTICES_MAX) { - printf("egraph error: maximum number of vertices reached !\n"); - goto err; - } + id = eg->vertices_freeids[eg->vertices_count]; + v->id = id; + eina_hash_add(eg->vertices, &id, v); + eg->vertices_count++; + v->v3_new = 1; + if (name) v->name = strndup(name, EGRAPH_VERTICE_NAME_MAXLEN); - else - v->name = NULL; - v->id = eg->vertices_freeids[eg->vertices_count]; - eg->vertices[v->id] = v; + + v->data = data; + + _layouting_schedule(eg); + return v; +} + +static void +_vertice_v2_add(Egraph *eg, Egraph_Vertice *v) +{ + v->v2_new = 1; + v->v3_new = 0; + + igraph_add_vertices(&eg->graph2, 1, 0); + SETVAN(&eg->graph2, "id", eg->graph2_vcount, v->id); + eg->graph2_vcount++; +} + +static void +_vertice_add(Egraph *eg, Egraph_Vertice *v) +{ + Evas_Object *vobj; + + v->new = 1; + v->v2_new = 0; igraph_add_vertices(&eg->graph, 1, 0); - eg->vertices_added++; - v->vertice_id = eg->vertices_count; - SETVAN(&eg->graph, "id", eg->vertices_count, v->id); - eg->vertices_count++; + SETVAN(&eg->graph, "id", eg->graph_vcount, v->id); + eg->graph_vcount++; vobj = evas_object_rectangle_add(eg->evas); - evas_object_smart_member_add(vobj, obj); + evas_object_smart_member_add(vobj, eg->obj); evas_object_color_set(vobj, 0, 0, 255, 255); evas_object_resize(vobj, VERTICE_OBJ_W, VERTICE_OBJ_H); v->o = vobj; - if (name) { - text = evas_object_text_add(eg->evas); - evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); - evas_object_color_set(text, 0, 255, 0, 255); - evas_object_text_font_set(text, "Vera-Bold", VERTICE_TEXT_H); - evas_object_text_text_set(text, name); - evas_object_smart_member_add(text, obj); - v->o_text = text; - } - v->data = data; - _layouting_schedule(eg); - return v; - -err: - if (v) - free(v); - return NULL; + if (v->name) + egraph_vertice_rename(eg->obj, v, v->name); } void @@ -222,32 +303,72 @@ egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v) { EGRAPH_DATA_GET(obj, eg); Egraph_Edge *e; - Eina_List *l, *lprev; + Eina_List *l; - EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) + v->v3_del = 1; + + EINA_LIST_FOREACH(eg->edges, l, e) if (e->a == v || e->b == v) egraph_edge_del(obj, e); - igraph_delete_vertices(&eg->graph, igraph_vss_1(v->vertice_id)); + _layouting_schedule(eg); +} + +static void +_vertice_v2_del(Egraph *eg, Egraph_Vertice *v) +{ + int pos; + + v->v2_del = 1; + v->v3_del = 0; + pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, v->id); + igraph_delete_vertices(&eg->graph2, igraph_vss_1(pos)); + eg->graph2_vcount--; +} + +static void +_vertice_del(Egraph *eg, Egraph_Vertice *v) +{ + int pos; + + pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, v->id); + igraph_delete_vertices(&eg->graph, igraph_vss_1(pos)); + eg->graph_vcount--; evas_object_del(v->o); + if (v->o_text) + evas_object_del(v->o_text); - eg->vertices_count--; + eina_hash_del(eg->vertices, &v->id, NULL); eg->vertices_freeids[eg->vertices_count] = v->id; + eg->vertices_count--; + free(v); - _layouting_schedule(eg); } -int -egraph_layout_set(Evas_Object *obj, const char *layout) +void +egraph_vertice_rename(Evas_Object *obj, Egraph_Vertice *v, const char *name) { EGRAPH_DATA_GET(obj, eg); + Evas_Object *text; - if (eg->layout) - free(eg->layout); - eg->layout = strndup(layout, 20); - - return 0; + if (name) { + if (!v->o_text) { + text = evas_object_text_add(eg->evas); + evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); + evas_object_color_set(text, 0, 255, 0, 255); + evas_object_text_font_set(text, "Vera-Bold", VERTICE_TEXT_H); + evas_object_smart_member_add(text, obj); + v->o_text = text; + } + evas_object_text_text_set(v->o_text, name); + evas_object_show(v->o_text); + } else { + if (v->o_text) { + evas_object_del(v->o_text); + v->o_text = NULL; + } + } } static void @@ -262,27 +383,94 @@ _layouting_schedule(Egraph *eg) ecore_timer_add(0.0, _cb_layouting_start, eg); /* delayed start */ } +// XXX IN PROGRESS +static void +_v2_update(Egraph *eg) +{ + Eina_List *l, *lprev; + Eina_Iterator *it; + Egraph_Vertice *v; + Egraph_Edge *e; + void *data; + + /* update graph and structs based on v2_add / v2_del */ + EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { + if (e->v2_del) + _edge_del(eg, e); + else if (e->v2_new) + _edge_add(eg, e); + } + it = eina_hash_iterator_tuple_new(eg->vertices); + while (eina_iterator_next(it, &data)) { + Eina_Hash_Tuple *t = data; + v = t->data; + if (v->v2_del) + _vertice_del(eg, v); + else if (v->v2_new) + _vertice_add(eg, v); + } +} + +static void +_v3_update(Egraph *eg) +{ + Eina_List *l, *lprev; + Eina_Iterator *it; + Egraph_Vertice *v; + Egraph_Edge *e; + void *data; + int changes_count = 0; + int changes_diff = 0; + int ranx, rany; + int i, id; + + /* update graph2 and structs based on v3_add / v3_del */ + EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { + if (e->v3_del) { + _edge_v2_del(eg, e); changes_count++; + } else if (e->v3_new) { + _edge_v2_add(eg, e); changes_count++; + } + } + it = eina_hash_iterator_tuple_new(eg->vertices); + while (eina_iterator_next(it, &data)) { + Eina_Hash_Tuple *t = data; + v = t->data; + if (v->v3_del) { + _vertice_v2_del(eg, v); changes_diff--; changes_count++; + } else if (v->v3_new) { + _vertice_v2_add(eg, v); changes_diff++; changes_count++; + } + } + eina_iterator_free(it); + + /* set correct coords2 size */ + if (changes_diff > 0) { + for (i=0; igraph2_vcount - changes_diff) + i; + igraph_matrix_add_rows(&eg->coords2, 1); + ranx = random() % 200; // XXX make this evas obj size ? + rany = random() % 200; // XXX make this evas obj size ? + igraph_matrix_set(&eg->coords2, id, 0, ranx); + igraph_matrix_set(&eg->coords2, id, 1, rany); + } + } else if (changes_diff < 0) { + igraph_matrix_remove_row(&eg->coords2, changes_diff); + } + + eg->layouting.changes_diff = changes_diff; +} + static Eina_Bool _cb_layouting_start(void *data) { Egraph *eg; - int ranx, rany; - int i, id; eg = data; eg->layouting.todo = 0; - for (i=0; ivertices_added; i++) { - id = (eg->vertices_count - eg->vertices_added) + i; - igraph_matrix_add_rows(&eg->graph_coords, 1); - ranx = random() % 200; - rany = random() % 200; - igraph_matrix_set(&eg->graph_coords, id, 0, ranx); - igraph_matrix_set(&eg->graph_coords, id, 1, rany); - } - eg->vertices_added = 0; - igraph_copy(&eg->layouting.graph, &eg->graph); + _v3_update(eg); eg->layouting.running = 2; eg->layouting.thread = ecore_thread_run(_cb_layouting_run, _cb_layouting_end, @@ -295,6 +483,7 @@ void _cb_layouting_run(void *data, Ecore_Thread *thread) { Egraph *eg; + int niter; eg = data; @@ -309,7 +498,7 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) const igraph_vector_t *maxx, const igraph_vector_t *miny, const igraph_vector_t *maxy); */ -/* igraph_layout_kamada_kawai(&eg->graph, &eg->graph_coords, +/* igraph_layout_kamada_kawai(&eg->graph2, &eg->coords2, 1000, eg->vertices_count / 4, 10, 0.99, eg->vertices_count ^ 2, 1, @@ -321,15 +510,19 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) igraph_real_t spring_constant, igraph_real_t max_sa_movement, igraph_bool_t use_seed); */ -/* igraph_layout_graphopt(&eg->graph, &eg->graph_coords, +/* igraph_layout_graphopt(&eg->graph2, &eg->coords2, 1000, 0.001, 10, 0, 1, 5, 1); */ - igraph_layout_graphopt(&eg->layouting.graph, &eg->graph_coords, - 1000, + printf("%d\n", eg->layouting.changes_diff); + niter = 50 * eg->layouting.changes_diff; + if (niter > 1000) + niter = 1000; + igraph_layout_graphopt(&eg->graph2, &eg->coords2, + niter, 0.003, 10, 0, 1, @@ -339,17 +532,25 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) printf("[-] _cb_layouting_run end\n"); } +static void +_coords2_copy(Egraph *eg) +{ + igraph_matrix_copy(&eg->coords, &eg->coords2); +} + void _cb_layouting_end(void *data, Ecore_Thread *thread) { Egraph *eg; eg = data; - eg->layouting.running = 0; + _v2_update(eg); + _coords2_copy(eg); _reposition(eg); + eg->layouting.running = 0; if (eg->layouting.todo) { - _layouting_schedule(eg); eg->layouting.todo = 0; + _layouting_schedule(eg); } } @@ -361,6 +562,21 @@ _cb_layouting_cancel(void *data, Ecore_Thread *thread) eg = data; eg->layouting.running = 0; eg->layouting.todo = 0; + /* we are not in a clean state now, but it happends on exit only */ +} + +/* XXX slow ! possible to do edge/vertice delete on repositionning ? */ +static int +_igraph_query_vid(igraph_t *g, int g_len, int id) +{ + int i; + + for (i=0; iobj, &obj_x, &obj_y, &obj_w, &obj_h); - _matrix_minmax_2v(&eg->graph_coords, eg->vertices_count, + _matrix_minmax_2v(&eg->coords, eg->vertices_count, &gw_min, &gw_max, &gh_min, &gh_max); if (DEBUG) printf("gw_min %6.3f gw_max %6.3f gh_min %6.3f gh_max %6.3f\n", @@ -393,8 +609,8 @@ _reposition(Egraph *eg) for (vcur=0; vcurvertices_count; vcur++) { id = VAN(&eg->graph, "id", vcur); - x = MATRIX(eg->graph_coords, vcur, 0); - y = MATRIX(eg->graph_coords, vcur, 1); + x = MATRIX(eg->coords, vcur, 0); + y = MATRIX(eg->coords, vcur, 1); if (DEBUG) printf("%d: %6.3f %6.3f id %d\n", vcur, x, y, id); x = obj_x + ((x - gw_min) * factor_w); @@ -402,20 +618,29 @@ _reposition(Egraph *eg) if (DEBUG) printf(" inobj: %6.3f %6.3f\n", x, y); - v = eg->vertices[id]; + v = eina_hash_find(eg->vertices, &id); evas_object_move(v->o, x, y); - evas_object_show(v->o); - if (v->name) { + if (v->o_text) evas_object_move(v->o_text, x+3, y+8); - evas_object_show(v->o_text); + + if (v->new) { + evas_object_show(v->o); + if (v->o_text) + evas_object_show(v->o_text); + v->new = 0; } } - EINA_LIST_FOREACH(eg->edges, l, e) { + EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { + if (e->v2_new || e->v3_new) + continue; evas_object_geometry_get(e->a->o, &x1, &y1, NULL, NULL); evas_object_geometry_get(e->b->o, &x2, &y2, NULL, NULL); evas_object_line_xy_set(e->o, x1, y1, x2, y2); - evas_object_show(e->o); + if (e->new) { + evas_object_show(e->o); + e->new = 0; + } } } -- cgit v1.2.3-59-g8ed1b From 661270876f83508b7a1107b3718f555cb6d58b2d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 05:16:16 +0100 Subject: fix graph / structs updating bugs --- egraph.c | 47 ++++++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/egraph.c b/egraph.c index 4726dd5..b8b7a51 100644 --- a/egraph.c +++ b/egraph.c @@ -317,10 +317,17 @@ egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v) static void _vertice_v2_del(Egraph *eg, Egraph_Vertice *v) { + Egraph_Edge *e; + Eina_List *l; int pos; v->v2_del = 1; v->v3_del = 0; + + EINA_LIST_FOREACH(eg->edges, l, e) + if (e->a == v || e->b == v) + _edge_v2_del(eg, e); + pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, v->id); igraph_delete_vertices(&eg->graph2, igraph_vss_1(pos)); eg->graph2_vcount--; @@ -329,8 +336,14 @@ _vertice_v2_del(Egraph *eg, Egraph_Vertice *v) static void _vertice_del(Egraph *eg, Egraph_Vertice *v) { + Egraph_Edge *e; + Eina_List *l; int pos; + EINA_LIST_FOREACH(eg->edges, l, e) + if (e->a == v || e->b == v) + _edge_del(eg, e); + pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, v->id); igraph_delete_vertices(&eg->graph, igraph_vss_1(pos)); eg->graph_vcount--; @@ -383,7 +396,6 @@ _layouting_schedule(Egraph *eg) ecore_timer_add(0.0, _cb_layouting_start, eg); /* delayed start */ } -// XXX IN PROGRESS static void _v2_update(Egraph *eg) { @@ -394,12 +406,6 @@ _v2_update(Egraph *eg) void *data; /* update graph and structs based on v2_add / v2_del */ - EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { - if (e->v2_del) - _edge_del(eg, e); - else if (e->v2_new) - _edge_add(eg, e); - } it = eina_hash_iterator_tuple_new(eg->vertices); while (eina_iterator_next(it, &data)) { Eina_Hash_Tuple *t = data; @@ -409,6 +415,13 @@ _v2_update(Egraph *eg) else if (v->v2_new) _vertice_add(eg, v); } + eina_iterator_free(it); + EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { + if (e->v2_del) + _edge_del(eg, e); + else if (e->v2_new) + _edge_add(eg, e); + } } static void @@ -425,13 +438,6 @@ _v3_update(Egraph *eg) int i, id; /* update graph2 and structs based on v3_add / v3_del */ - EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { - if (e->v3_del) { - _edge_v2_del(eg, e); changes_count++; - } else if (e->v3_new) { - _edge_v2_add(eg, e); changes_count++; - } - } it = eina_hash_iterator_tuple_new(eg->vertices); while (eina_iterator_next(it, &data)) { Eina_Hash_Tuple *t = data; @@ -443,6 +449,13 @@ _v3_update(Egraph *eg) } } eina_iterator_free(it); + EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { + if (e->v3_del) { + _edge_v2_del(eg, e); changes_count++; + } else if (e->v3_new) { + _edge_v2_add(eg, e); changes_count++; + } + } /* set correct coords2 size */ if (changes_diff > 0) { @@ -487,7 +500,7 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) eg = data; - if (DEBUG) + //if (DEBUG) printf("[-] _cb_layouting_run begin\n"); /* int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, @@ -528,7 +541,7 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) 1, 5, 1); - if (DEBUG) + //if (DEBUG) printf("[-] _cb_layouting_run end\n"); } @@ -571,7 +584,7 @@ _igraph_query_vid(igraph_t *g, int g_len, int id) { int i; - for (i=0; i Date: Sat, 8 Dec 2012 05:19:01 +0100 Subject: fix edge Evas_Object_Line attachement position in vertice --- egraph.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/egraph.c b/egraph.c index b8b7a51..d459efa 100644 --- a/egraph.c +++ b/egraph.c @@ -602,7 +602,7 @@ _reposition(Egraph *eg) float gw_min, gw_max, gh_min, gh_max, factor_w, factor_h; float x, y; int obj_x, obj_y, obj_w, obj_h; - int x1, x2, y1, y2; + int x1, x2, y1, y2, w1, w2, h1, h2; int vcur; if (DEBUG) @@ -647,9 +647,9 @@ _reposition(Egraph *eg) EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { if (e->v2_new || e->v3_new) continue; - evas_object_geometry_get(e->a->o, &x1, &y1, NULL, NULL); - evas_object_geometry_get(e->b->o, &x2, &y2, NULL, NULL); - evas_object_line_xy_set(e->o, x1, y1, x2, y2); + evas_object_geometry_get(e->a->o, &x1, &y1, &w1, &h1); + evas_object_geometry_get(e->b->o, &x2, &y2, &w2, &h2); + evas_object_line_xy_set(e->o, x1+w1/2, y1+h1/2, x2+w2/2, y2+h2/2); if (e->new) { evas_object_show(e->o); e->new = 0; -- cgit v1.2.3-59-g8ed1b From cf402c3347a0ca2d65f24a2a53d5048925f5a81d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 05:22:18 +0100 Subject: put algo for layouting in Internals section --- README.txt | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/README.txt b/README.txt index ff535cd..abc5f89 100644 --- a/README.txt +++ b/README.txt @@ -23,6 +23,21 @@ sudo make install TODO ==== +* possible future API: no edges no vertices for the user + +struct Egraph_Vertice { + const char *name; + int vertice_id; + Evas_Object *o; + void *data; +} +egraph_vertice_add(Egraph *eg, const char *name, void *data); +egraph_edge_add(Egraph *eg, + const char *a, const char *b, void *data); + +Internals +========= + === algo to handle threaded graph layouting correctly === ###### GENERAL ALGO @@ -109,15 +124,3 @@ _v2_update(); ###### TIMELINE VERTICE DEL -=== possible future API: no edges no vertices for the user === - -struct Egraph_Vertice { - const char *name; - int vertice_id; - Evas_Object *o; - void *data; -} -egraph_vertice_add(Egraph *eg, const char *name, void *data); -egraph_edge_add(Egraph *eg, - const char *a, const char *b, void *data); - -- cgit v1.2.3-59-g8ed1b From a359e0e1d6ed560c4287d0cd3e7d8dd9e92aa528 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 05:30:10 +0100 Subject: oops, remove extra variable definition --- examples/interactive.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/interactive.c b/examples/interactive.c index 3019c72..7d831df 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -55,8 +55,6 @@ elm_main(int argc, char **argv) { Evas_Object *win, *bg, *bx, *panes, *tb, *egraph; Evas *evas; - Ecore_Timer *timer_libevent; - struct gg_client *ggcli; int retval = -1; win = elm_win_add(NULL, "panes", ELM_WIN_BASIC); -- cgit v1.2.3-59-g8ed1b From 7e3e28bb8fdd87c088152821c48401c49f42cd30 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 06:00:34 +0100 Subject: add a way to disable vertice name display --- Egraph.h | 6 ++++++ egraph.c | 48 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/Egraph.h b/Egraph.h index ae53bc5..7c395ee 100644 --- a/Egraph.h +++ b/Egraph.h @@ -19,6 +19,7 @@ struct Egraph { Evas_Object *obj; Evas *evas; int graph_directed; + int display_names; Egraph_Layout layout; struct { Ecore_Thread *thread; @@ -73,6 +74,11 @@ Evas_Object *egraph_new(Evas *evas, int directed); */ void egraph_layout_set(Evas_Object *obj, Egraph_Layout layout); +/** + * Configure if Egraph should display vertices names + */ +void egraph_display_names_set(Evas_Object *obj, int set); + /** * Adds an edge between existing vertices * diff --git a/egraph.c b/egraph.c index d459efa..9cf894c 100644 --- a/egraph.c +++ b/egraph.c @@ -111,6 +111,7 @@ egraph_new(Evas *evas, int directed) eg->obj = obj; eg->graph_directed = directed; + eg->display_names = 1; eg->layout = EGRAPH_LAYOUT_GRAPHOPT; /* needed for igraph attribute handling */ @@ -143,6 +144,27 @@ egraph_layout_set(Evas_Object *obj, Egraph_Layout layout) _layouting_schedule(eg); } +void +egraph_display_names_set(Evas_Object *obj, int set) +{ + EGRAPH_DATA_GET(obj, eg); + Eina_Iterator *it; + Egraph_Vertice *v; + void *data; + + eg->display_names = set; + + it = eina_hash_iterator_tuple_new(eg->vertices); + while (eina_iterator_next(it, &data)) { + Eina_Hash_Tuple *t = data; + v = t->data; + if (set == 0) + evas_object_hide(v->o_text); + else + evas_object_show(v->o_text); + } +} + Egraph_Edge * egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, void *data) @@ -279,7 +301,7 @@ _vertice_v2_add(Egraph *eg, Egraph_Vertice *v) static void _vertice_add(Egraph *eg, Egraph_Vertice *v) { - Evas_Object *vobj; + Evas_Object *vobj, *text; v->new = 1; v->v2_new = 0; @@ -294,6 +316,13 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) evas_object_resize(vobj, VERTICE_OBJ_W, VERTICE_OBJ_H); v->o = vobj; + text = evas_object_text_add(eg->evas); + evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); + evas_object_color_set(text, 0, 255, 0, 255); + evas_object_text_font_set(text, "Vera-Bold", VERTICE_TEXT_H); + evas_object_smart_member_add(text, eg->obj); + v->o_text = text; + if (v->name) egraph_vertice_rename(eg->obj, v, v->name); } @@ -363,24 +392,15 @@ void egraph_vertice_rename(Evas_Object *obj, Egraph_Vertice *v, const char *name) { EGRAPH_DATA_GET(obj, eg); - Evas_Object *text; + + if (eg->display_names == 0) + return; if (name) { - if (!v->o_text) { - text = evas_object_text_add(eg->evas); - evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); - evas_object_color_set(text, 0, 255, 0, 255); - evas_object_text_font_set(text, "Vera-Bold", VERTICE_TEXT_H); - evas_object_smart_member_add(text, obj); - v->o_text = text; - } evas_object_text_text_set(v->o_text, name); evas_object_show(v->o_text); } else { - if (v->o_text) { - evas_object_del(v->o_text); - v->o_text = NULL; - } + evas_object_hide(v->o_text); } } -- cgit v1.2.3-59-g8ed1b From 8987642415580264a544d4a6ca86e55a672e805f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 06:02:03 +0100 Subject: add a checkbox to display vertice names or not --- examples/interactive.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/examples/interactive.c b/examples/interactive.c index 7d831df..202349f 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -44,6 +44,14 @@ _cb_add_500edges(void *data, Evas_Object *obj, void *event_info) _cb_add_edge(data, obj, event_info); } +static void +_cb_showlabel(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *ck = data; + + egraph_display_names_set(_egraph, elm_check_state_get(obj)); +} + static void _cb_on_done(void *data, Evas_Object *obj, void *event_info) { @@ -53,7 +61,7 @@ _cb_on_done(void *data, Evas_Object *obj, void *event_info) EAPI_MAIN int elm_main(int argc, char **argv) { - Evas_Object *win, *bg, *bx, *panes, *tb, *egraph; + Evas_Object *win, *bg, *bx, *panes, *tb, *tb_it, *ck, *egraph; Evas *evas; int retval = -1; @@ -91,6 +99,13 @@ elm_main(int argc, char **argv) _cb_add_50edges, NULL); elm_toolbar_item_append(tb, "object-rotate-right", "Add 500 edges", _cb_add_500edges, NULL); + ck = elm_check_add(win); + elm_object_text_set(ck, "Show Label"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_showlabel, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); elm_toolbar_item_append(tb, "exit", "Quit", _cb_on_done, NULL); elm_object_part_content_set(panes, "left", tb); -- cgit v1.2.3-59-g8ed1b From 5bd290348cbfc12666087bf34d713d933d278c7b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 06:26:27 +0100 Subject: add API calls to select wether to display vertices or edges --- Egraph.h | 12 ++++++++++++ egraph.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 67 insertions(+), 8 deletions(-) diff --git a/Egraph.h b/Egraph.h index 7c395ee..78cac0d 100644 --- a/Egraph.h +++ b/Egraph.h @@ -19,7 +19,9 @@ struct Egraph { Evas_Object *obj; Evas *evas; int graph_directed; + int display_vertices; int display_names; + int display_edges; Egraph_Layout layout; struct { Ecore_Thread *thread; @@ -74,11 +76,21 @@ Evas_Object *egraph_new(Evas *evas, int directed); */ void egraph_layout_set(Evas_Object *obj, Egraph_Layout layout); +/** + * Configure if Egraph should display vertices + */ +void egraph_display_vertices_set(Evas_Object *obj, int set); + /** * Configure if Egraph should display vertices names */ void egraph_display_names_set(Evas_Object *obj, int set); +/** + * Configure if Egraph should display edges + */ +void egraph_display_edges_set(Evas_Object *obj, int set); + /** * Adds an edge between existing vertices * diff --git a/egraph.c b/egraph.c index 9cf894c..c00b07b 100644 --- a/egraph.c +++ b/egraph.c @@ -111,7 +111,9 @@ egraph_new(Evas *evas, int directed) eg->obj = obj; eg->graph_directed = directed; + eg->display_vertices = 1; eg->display_names = 1; + eg->display_edges = 1; eg->layout = EGRAPH_LAYOUT_GRAPHOPT; /* needed for igraph attribute handling */ @@ -144,6 +146,29 @@ egraph_layout_set(Evas_Object *obj, Egraph_Layout layout) _layouting_schedule(eg); } +void +egraph_display_vertices_set(Evas_Object *obj, int set) +{ + EGRAPH_DATA_GET(obj, eg); + Eina_Iterator *it; + Egraph_Vertice *v; + void *data; + + eg->display_vertices = set; + + it = eina_hash_iterator_tuple_new(eg->vertices); + while (eina_iterator_next(it, &data)) { + Eina_Hash_Tuple *t = data; + v = t->data; + if (v->o) { + if (set == 0) + evas_object_hide(v->o); + else + evas_object_show(v->o); + } + } +} + void egraph_display_names_set(Evas_Object *obj, int set) { @@ -158,10 +183,31 @@ egraph_display_names_set(Evas_Object *obj, int set) while (eina_iterator_next(it, &data)) { Eina_Hash_Tuple *t = data; v = t->data; - if (set == 0) - evas_object_hide(v->o_text); - else - evas_object_show(v->o_text); + if (v->o_text) { + if (set == 0) + evas_object_hide(v->o_text); + else + evas_object_show(v->o_text); + } + } +} + +void +egraph_display_edges_set(Evas_Object *obj, int set) +{ + EGRAPH_DATA_GET(obj, eg); + Eina_List *l; + Egraph_Edge *e; + + eg->display_edges = set; + + EINA_LIST_FOREACH(eg->edges, l, e) { + if (e->o) { + if (set == 0) + evas_object_hide(e->o); + else + evas_object_show(e->o); + } } } @@ -655,10 +701,10 @@ _reposition(Egraph *eg) evas_object_move(v->o, x, y); if (v->o_text) evas_object_move(v->o_text, x+3, y+8); - if (v->new) { - evas_object_show(v->o); - if (v->o_text) + if (eg->display_vertices) + evas_object_show(v->o); + if (v->o_text && eg->display_names) evas_object_show(v->o_text); v->new = 0; } @@ -671,7 +717,8 @@ _reposition(Egraph *eg) evas_object_geometry_get(e->b->o, &x2, &y2, &w2, &h2); evas_object_line_xy_set(e->o, x1+w1/2, y1+h1/2, x2+w2/2, y2+h2/2); if (e->new) { - evas_object_show(e->o); + if (eg->display_edges) + evas_object_show(e->o); e->new = 0; } } -- cgit v1.2.3-59-g8ed1b From d282e4760765e2d6eebdae25c6177a84eb8cceee Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 06:27:17 +0100 Subject: add buttons to display or not vertices and edges --- examples/interactive.c | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/examples/interactive.c b/examples/interactive.c index 202349f..e4f232a 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -45,11 +45,21 @@ _cb_add_500edges(void *data, Evas_Object *obj, void *event_info) } static void -_cb_showlabel(void *data, Evas_Object *obj, void *event_info) +_cb_show_nodes(void *data, Evas_Object *obj, void *event_info) { - Evas_Object *ck = data; + egraph_display_vertices_set(_egraph, elm_check_state_get(obj)); +} - egraph_display_names_set(_egraph, elm_check_state_get(obj)); +static void +_cb_show_labels(void *data, Evas_Object *obj, void *event_info) +{ + egraph_display_names_set(_egraph, elm_check_state_get(obj)); +} + +static void +_cb_show_edges(void *data, Evas_Object *obj, void *event_info) +{ + egraph_display_edges_set(_egraph, elm_check_state_get(obj)); } static void @@ -99,13 +109,31 @@ elm_main(int argc, char **argv) _cb_add_50edges, NULL); elm_toolbar_item_append(tb, "object-rotate-right", "Add 500 edges", _cb_add_500edges, NULL); + elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); + ck = elm_check_add(win); + elm_object_text_set(ck, "Show Node"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_show_nodes, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); + elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); ck = elm_check_add(win); elm_object_text_set(ck, "Show Label"); elm_check_state_set(ck, EINA_TRUE); evas_object_show(ck); - evas_object_smart_callback_add(ck, "changed", _cb_showlabel, NULL); + evas_object_smart_callback_add(ck, "changed", _cb_show_labels, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); + elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); + ck = elm_check_add(win); + elm_object_text_set(ck, "Show Edges"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_show_edges, NULL); tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", ck); + elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); elm_toolbar_item_append(tb, "exit", "Quit", _cb_on_done, NULL); elm_object_part_content_set(panes, "left", tb); -- cgit v1.2.3-59-g8ed1b From 796ebcc66111fab320ca5657d1f854fab5bd87cc Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 06:29:53 +0100 Subject: if we do not display vertices, display vertices text in place --- egraph.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index c00b07b..da61d1e 100644 --- a/egraph.c +++ b/egraph.c @@ -167,6 +167,8 @@ egraph_display_vertices_set(Evas_Object *obj, int set) evas_object_show(v->o); } } + + _reposition(eg); } void @@ -699,8 +701,12 @@ _reposition(Egraph *eg) v = eina_hash_find(eg->vertices, &id); evas_object_move(v->o, x, y); - if (v->o_text) - evas_object_move(v->o_text, x+3, y+8); + if (v->o_text) { + if (eg->display_vertices) + evas_object_move(v->o_text, x+3, y+8); + else + evas_object_move(v->o_text, x, y); + } if (v->new) { if (eg->display_vertices) evas_object_show(v->o); -- cgit v1.2.3-59-g8ed1b From df07958227ce4fbcf5113b6de4b6acbf9f1a24cf Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 06:33:48 +0100 Subject: BUG++ --- README.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.txt b/README.txt index abc5f89..c9cb571 100644 --- a/README.txt +++ b/README.txt @@ -23,6 +23,9 @@ sudo make install TODO ==== +* BUG: in _reposition(): +when you do _reposition during layouting, the graph is broken + * possible future API: no edges no vertices for the user struct Egraph_Vertice { -- cgit v1.2.3-59-g8ed1b From 669411be5c39a923582127bc721a2817a4b39e94 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 06:42:33 +0100 Subject: oops, fix bug in _repositionning where i was using the wrong vertices count --- egraph.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/egraph.c b/egraph.c index da61d1e..79220a1 100644 --- a/egraph.c +++ b/egraph.c @@ -675,11 +675,11 @@ _reposition(Egraph *eg) if (DEBUG) printf("[-] _reposition\n"); - if (eg->vertices_count == 0) + if (eg->graph_vcount == 0) return; evas_object_geometry_get(eg->obj, &obj_x, &obj_y, &obj_w, &obj_h); - _matrix_minmax_2v(&eg->coords, eg->vertices_count, + _matrix_minmax_2v(&eg->coords, eg->graph_vcount, &gw_min, &gw_max, &gh_min, &gh_max); if (DEBUG) printf("gw_min %6.3f gw_max %6.3f gh_min %6.3f gh_max %6.3f\n", @@ -687,7 +687,7 @@ _reposition(Egraph *eg) factor_w = (obj_w - VERTICE_W) / (gw_max - gw_min); factor_h = (obj_h - VERTICE_H) / (gh_max - gh_min); - for (vcur=0; vcurvertices_count; vcur++) { + for (vcur=0; vcurgraph_vcount; vcur++) { id = VAN(&eg->graph, "id", vcur); x = MATRIX(eg->coords, vcur, 0); -- cgit v1.2.3-59-g8ed1b From a3dc6de06144216cf9e008483eaa7b51de30fc88 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 06:43:33 +0100 Subject: BUG-- BUG++ --- README.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.txt b/README.txt index c9cb571..a0abb64 100644 --- a/README.txt +++ b/README.txt @@ -23,8 +23,7 @@ sudo make install TODO ==== -* BUG: in _reposition(): -when you do _reposition during layouting, the graph is broken +* BUG: when you add nodes during layouting, the graph is broken * possible future API: no edges no vertices for the user -- cgit v1.2.3-59-g8ed1b From 81552b8cb4d3e2acebd6edfe753a69845296cee1 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 07:07:15 +0100 Subject: precisions on BUG --- README.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.txt b/README.txt index a0abb64..8bae592 100644 --- a/README.txt +++ b/README.txt @@ -23,7 +23,7 @@ sudo make install TODO ==== -* BUG: when you add nodes during layouting, the graph is broken +* BUG: sometimes when you add nodes during layouting, the graph is broken * possible future API: no edges no vertices for the user -- cgit v1.2.3-59-g8ed1b From bceb65c8b8015da9b5498745c4abb363f61cbba3 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 07:28:25 +0100 Subject: node name is now node number --- examples/interactive.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/interactive.c b/examples/interactive.c index e4f232a..8ee16ee 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -5,12 +5,14 @@ Evas_Object *_mainwin, *_egraph; Eina_List *_vertice_list = NULL; +int _count = 0; static void _cb_add_edge(void *data, Evas_Object *obj, void *event_info) { Egraph_Vertice *a, *b; int ran, count; + char buf[64]; count = eina_list_count(_vertice_list); if (count == 0) { @@ -20,7 +22,9 @@ _cb_add_edge(void *data, Evas_Object *obj, void *event_info) ran = random() % count; a = eina_list_nth(_vertice_list, ran); } - b = egraph_vertice_add(_egraph, "node", NULL); + snprintf(buf, sizeof(buf), "%d", _count); + _count++; + b = egraph_vertice_add(_egraph, buf, NULL); _vertice_list = eina_list_append(_vertice_list, b); egraph_edge_add(_egraph, a, b, NULL); -- cgit v1.2.3-59-g8ed1b From 3721691879020b05cea88066af72b732e4388d57 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 07:46:36 +0100 Subject: more bug details --- README.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.txt b/README.txt index 8bae592..d893195 100644 --- a/README.txt +++ b/README.txt @@ -24,6 +24,8 @@ TODO ==== * BUG: sometimes when you add nodes during layouting, the graph is broken +a new edge attaches to the wrong new vertice +it seems to be always the same node numbers that gets this wrong edge * possible future API: no edges no vertices for the user -- cgit v1.2.3-59-g8ed1b From d304765d8fa18acf290044cdca42d3e2417c7587 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 07:46:56 +0100 Subject: add button to delete all vertices --- examples/interactive.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/interactive.c b/examples/interactive.c index 8ee16ee..b3606c2 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -48,6 +48,18 @@ _cb_add_500edges(void *data, Evas_Object *obj, void *event_info) _cb_add_edge(data, obj, event_info); } +static void +_cb_del_edges(void *data, Evas_Object *obj, void *event_info) +{ + Eina_List *l; + Egraph_Vertice *v; + + EINA_LIST_FOREACH(_vertice_list, l, v) + egraph_vertice_del(_egraph, v); + + _vertice_list = eina_list_free(_vertice_list); +} + static void _cb_show_nodes(void *data, Evas_Object *obj, void *event_info) { @@ -113,6 +125,8 @@ elm_main(int argc, char **argv) _cb_add_50edges, NULL); elm_toolbar_item_append(tb, "object-rotate-right", "Add 500 edges", _cb_add_500edges, NULL); + elm_toolbar_item_append(tb, "object-rotate-right", "Delete all", + _cb_del_edges, NULL); elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); ck = elm_check_add(win); elm_object_text_set(ck, "Show Node"); -- cgit v1.2.3-59-g8ed1b From f5cb2439984ccccc2dc61f9e2ada3c2d7a2821dc Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 08:35:51 +0100 Subject: make the values on 1bit u_int --- Egraph.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Egraph.h b/Egraph.h index 78cac0d..91340f5 100644 --- a/Egraph.h +++ b/Egraph.h @@ -47,11 +47,11 @@ struct Egraph_Vertice { Evas_Object *o; Evas_Object *o_text; void *data; - int new : 1; - int v2_new : 1; - int v2_del : 1; - int v3_new : 1; - int v3_del : 1; + u_int new : 1; + u_int v2_new : 1; + u_int v2_del : 1; + u_int v3_new : 1; + u_int v3_del : 1; }; struct Egraph_Edge { @@ -59,11 +59,11 @@ struct Egraph_Edge { Egraph_Vertice *b; Evas_Object *o; void *data; - int new : 1; - int v2_new : 1; - int v2_del : 1; - int v3_new : 1; - int v3_del : 1; + u_int new : 1; + u_int v2_new : 1; + u_int v2_del : 1; + u_int v3_new : 1; + u_int v3_del : 1; }; /** -- cgit v1.2.3-59-g8ed1b From a96d1f41a5ba1aa8c1a197661524c188b9d2f7e5 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 08:36:23 +0100 Subject: BUG++ --- README.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.txt b/README.txt index d893195..6e01571 100644 --- a/README.txt +++ b/README.txt @@ -27,6 +27,8 @@ TODO a new edge attaches to the wrong new vertice it seems to be always the same node numbers that gets this wrong edge +* BUG: when adding 2 edges and removing them, it creates instability + * possible future API: no edges no vertices for the user struct Egraph_Vertice { -- cgit v1.2.3-59-g8ed1b From 2b59ee2c9b6850e93a7d5c4999ba57b56de3d8a9 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 16:56:50 +0100 Subject: TODO++ --- README.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.txt b/README.txt index 6e01571..ec5623b 100644 --- a/README.txt +++ b/README.txt @@ -29,6 +29,10 @@ it seems to be always the same node numbers that gets this wrong edge * BUG: when adding 2 edges and removing them, it creates instability +* find a better storage type for vertices +quick access O(1) -> table +possibility to foreach and remove at the same time + * possible future API: no edges no vertices for the user struct Egraph_Vertice { -- cgit v1.2.3-59-g8ed1b From e7e387ea6fe6266beb1e82b639325ca1ce47db6e Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 16:59:50 +0100 Subject: set node name to node id --- examples/interactive.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/interactive.c b/examples/interactive.c index b3606c2..2287f34 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -5,7 +5,6 @@ Evas_Object *_mainwin, *_egraph; Eina_List *_vertice_list = NULL; -int _count = 0; static void _cb_add_edge(void *data, Evas_Object *obj, void *event_info) @@ -22,9 +21,9 @@ _cb_add_edge(void *data, Evas_Object *obj, void *event_info) ran = random() % count; a = eina_list_nth(_vertice_list, ran); } - snprintf(buf, sizeof(buf), "%d", _count); - _count++; - b = egraph_vertice_add(_egraph, buf, NULL); + b = egraph_vertice_add(_egraph, NULL, NULL); + snprintf(buf, sizeof(buf), "%d", b->id); + egraph_vertice_rename(_egraph, b, buf); _vertice_list = eina_list_append(_vertice_list, b); egraph_edge_add(_egraph, a, b, NULL); -- cgit v1.2.3-59-g8ed1b From b1881d5d7eaf3c7938d04ad6e6112b3a2f58567b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 17:00:04 +0100 Subject: fixes fixes ! * fix vertice name / rename * fix vertice deletion * fix vertice freeids table when deleting a vertice * add some DEBUG printf --- Egraph.h | 2 +- egraph.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/Egraph.h b/Egraph.h index 91340f5..4577bc8 100644 --- a/Egraph.h +++ b/Egraph.h @@ -43,7 +43,7 @@ struct Egraph { struct Egraph_Vertice { u_int32_t id; - const char *name; + char *name; Evas_Object *o; Evas_Object *o_text; void *data; diff --git a/egraph.c b/egraph.c index 79220a1..5b3f250 100644 --- a/egraph.c +++ b/egraph.c @@ -228,6 +228,8 @@ egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, e->b = b; e->data = data; eg->edges = eina_list_append(eg->edges, e); + if (DEBUG) + printf("egraph_edge_add %d %d\n", e->a->id, e->b->id); _layouting_schedule(eg); return e; @@ -238,6 +240,9 @@ _edge_v2_add(Egraph *eg, Egraph_Edge *e) { int a_pos, b_pos; + if (DEBUG) + printf("_edge_v2_add %d %d\n", e->a->id, e->b->id); + e->v2_new = 1; e->v3_new = 0; @@ -279,6 +284,12 @@ _edge_v2_del(Egraph *eg, Egraph_Edge *e) { igraph_es_t es; int a_pos, b_pos; + + if (e->v2_del == 1) + return; + + if (DEBUG) + printf("_edge_v2_del %d %d\n", e->a->id, e->b->id); e->v2_del = 1; e->v3_del = 0; @@ -325,6 +336,8 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) eina_hash_add(eg->vertices, &id, v); eg->vertices_count++; v->v3_new = 1; + if (DEBUG) + printf("egraph_vertice_add %d\n", id); if (name) v->name = strndup(name, EGRAPH_VERTICE_NAME_MAXLEN); @@ -398,9 +411,14 @@ _vertice_v2_del(Egraph *eg, Egraph_Vertice *v) Eina_List *l; int pos; + if (v->v2_del == 1) + return; + v->v2_del = 1; v->v3_del = 0; + if (DEBUG) + printf("_vertice_v2_del %d\n", v->id); EINA_LIST_FOREACH(eg->edges, l, e) if (e->a == v || e->b == v) _edge_v2_del(eg, e); @@ -430,8 +448,8 @@ _vertice_del(Egraph *eg, Egraph_Vertice *v) evas_object_del(v->o_text); eina_hash_del(eg->vertices, &v->id, NULL); - eg->vertices_freeids[eg->vertices_count] = v->id; eg->vertices_count--; + eg->vertices_freeids[eg->vertices_count] = v->id; free(v); } @@ -445,6 +463,11 @@ egraph_vertice_rename(Evas_Object *obj, Egraph_Vertice *v, const char *name) return; if (name) { + if (v->name != name) { + if (v->name) + free(v->name); + v->name = strndup(name, EGRAPH_VERTICE_NAME_MAXLEN); + } evas_object_text_text_set(v->o_text, name); evas_object_show(v->o_text); } else { @@ -467,7 +490,7 @@ _layouting_schedule(Egraph *eg) static void _v2_update(Egraph *eg) { - Eina_List *l, *lprev; + Eina_List *l, *lprev, *todel, *toadd; Eina_Iterator *it; Egraph_Vertice *v; Egraph_Edge *e; @@ -475,15 +498,22 @@ _v2_update(Egraph *eg) /* update graph and structs based on v2_add / v2_del */ it = eina_hash_iterator_tuple_new(eg->vertices); + todel = NULL; toadd = NULL; while (eina_iterator_next(it, &data)) { Eina_Hash_Tuple *t = data; v = t->data; if (v->v2_del) - _vertice_del(eg, v); + todel = eina_list_append(todel, v); else if (v->v2_new) - _vertice_add(eg, v); + toadd = eina_list_append(toadd, v); } eina_iterator_free(it); + EINA_LIST_FOREACH(todel, l, v) + _vertice_del(eg, v); + EINA_LIST_FOREACH(toadd, l, v) + _vertice_add(eg, v); + todel = eina_list_free(todel); + toadd = eina_list_free(toadd); EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { if (e->v2_del) _edge_del(eg, e); @@ -505,6 +535,8 @@ _v3_update(Egraph *eg) int ranx, rany; int i, id; + if (DEBUG) + printf("_v3_update\n"); /* update graph2 and structs based on v3_add / v3_del */ it = eina_hash_iterator_tuple_new(eg->vertices); while (eina_iterator_next(it, &data)) { @@ -517,6 +549,8 @@ _v3_update(Egraph *eg) } } eina_iterator_free(it); + if (DEBUG) + printf("_v3_update edges\n"); EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { if (e->v3_del) { _edge_v2_del(eg, e); changes_count++; @@ -536,7 +570,11 @@ _v3_update(Egraph *eg) igraph_matrix_set(&eg->coords2, id, 1, rany); } } else if (changes_diff < 0) { - igraph_matrix_remove_row(&eg->coords2, changes_diff); + changes_diff = -changes_diff; + for (i=0; igraph2_vcount + changes_diff) - i; + igraph_matrix_remove_row(&eg->coords2, 0); + } } eg->layouting.changes_diff = changes_diff; @@ -568,7 +606,7 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) eg = data; - //if (DEBUG) + if (DEBUG) printf("[-] _cb_layouting_run begin\n"); /* int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, @@ -598,7 +636,6 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) 1, 5, 1); */ - printf("%d\n", eg->layouting.changes_diff); niter = 50 * eg->layouting.changes_diff; if (niter > 1000) niter = 1000; @@ -609,7 +646,7 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) 1, 5, 1); - //if (DEBUG) + if (DEBUG) printf("[-] _cb_layouting_run end\n"); } -- cgit v1.2.3-59-g8ed1b From 76468915d1ad6b1965ffdb4958f2c1c7ad3dba76 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 17:02:35 +0100 Subject: BUG-- --- README.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.txt b/README.txt index ec5623b..d6cbc38 100644 --- a/README.txt +++ b/README.txt @@ -27,8 +27,6 @@ TODO a new edge attaches to the wrong new vertice it seems to be always the same node numbers that gets this wrong edge -* BUG: when adding 2 edges and removing them, it creates instability - * find a better storage type for vertices quick access O(1) -> table possibility to foreach and remove at the same time -- cgit v1.2.3-59-g8ed1b From 3f3d20707b84c90b50fec2bdb23c545d0f78f38a Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 17:10:14 +0100 Subject: move TODO and internals to their own text file --- README.txt | 112 ------------------------------------------------------ doc/TODO.txt | 23 +++++++++++ doc/internals.txt | 89 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 112 deletions(-) create mode 100644 doc/TODO.txt create mode 100644 doc/internals.txt diff --git a/README.txt b/README.txt index d6cbc38..1248c36 100644 --- a/README.txt +++ b/README.txt @@ -20,115 +20,3 @@ Installation make sudo make install -TODO -==== - -* BUG: sometimes when you add nodes during layouting, the graph is broken -a new edge attaches to the wrong new vertice -it seems to be always the same node numbers that gets this wrong edge - -* find a better storage type for vertices -quick access O(1) -> table -possibility to foreach and remove at the same time - -* possible future API: no edges no vertices for the user - -struct Egraph_Vertice { - const char *name; - int vertice_id; - Evas_Object *o; - void *data; -} -egraph_vertice_add(Egraph *eg, const char *name, void *data); -egraph_edge_add(Egraph *eg, - const char *a, const char *b, void *data); - -Internals -========= - -=== algo to handle threaded graph layouting correctly === - -###### GENERAL ALGO -_layouting_start(graph-2, coords-2); - -_add/del(structs-3); -_repositionning(graph, structs, coords); - -_layouting_end(coords-2); - -_v2_updtate(structs-2, graph-2, coords-2); - _v2_structs/graph_update(structs-2, graph); - -> structs, graph // real add/del - _coords_copy(coords-2); - -> coords - -_repositionning(graph, structs, coords); - -_v3_update(structs-3); - _v3_structs/graph_update(structs-3, graph-2); - -> structs-2, graph-2 - -###### TIMELINE VERTICE ADD -egraph_vertice_add(); - id = freeids[vertices_count]; - v = vertices[id]; - v->id = id; - vertices_count++; - v->v3-new = 1; - -_v3_update(); - v->v2-new = v->v3-new; - v->v3-new = 0; - _v2_add() - v->graph2_vid = graph2_vcount; - graph2_vcount++; - igraph_add_vertices(graph2); - -_layouting_start(); - // end up in coords2 - -_layouting_end(); -_coords_copy(); - // end up in coords - -_v2_update(); - _add() - v->v2-new = 0; - v->graph_vid = graph_vcount; - graph_vcount++; - igraph_add_vertices(graph); - evas_object - -// in structs, graph, coords - -###### TIMELINE VERTICE DEL -egraph_vertice_del(); - v->v3-del = 1; - -_v3_update(); - v->v2-del = v->v3-del; - v->v3-del = 0; - _v2_del() - igraph_delete_vertices(v->graph2_vid); - graph2_vcount--; - -_layouting_start(); - // not in coords2 - -_layouting_end(); -_coords_copy(); - // not in coords - -_v2_update(); - _del(); - igraph_delete_vertices(v->graph_vid); - graph_vcount--; - freeids[vertices_count] = v->id; - vertices_count--; - free(v); - -// removed from structs, graph, coords - -###### TIMELINE VERTICE DEL - - diff --git a/doc/TODO.txt b/doc/TODO.txt new file mode 100644 index 0000000..5b59c03 --- /dev/null +++ b/doc/TODO.txt @@ -0,0 +1,23 @@ +TODO +==== + +* BUG: sometimes when you add nodes during layouting, the graph is broken +a new edge attaches to the wrong new vertice +it seems to be always the same node numbers that gets this wrong edge + +* find a better storage type for vertices +quick access O(1) -> table +possibility to foreach and remove at the same time + +* possible future API: no edges no vertices for the user + +struct Egraph_Vertice { + const char *name; + int vertice_id; + Evas_Object *o; + void *data; +} +egraph_vertice_add(Egraph *eg, const char *name, void *data); +egraph_edge_add(Egraph *eg, + const char *a, const char *b, void *data); + diff --git a/doc/internals.txt b/doc/internals.txt new file mode 100644 index 0000000..7a8b34d --- /dev/null +++ b/doc/internals.txt @@ -0,0 +1,89 @@ +Internals +========= + +=== algo to handle threaded graph layouting correctly === + +###### GENERAL ALGO +_layouting_start(graph-2, coords-2); + +_add/del(structs-3); +_repositionning(graph, structs, coords); + +_layouting_end(coords-2); + +_v2_updtate(structs-2, graph-2, coords-2); + _v2_structs/graph_update(structs-2, graph); + -> structs, graph // real add/del + _coords_copy(coords-2); + -> coords + +_repositionning(graph, structs, coords); + +_v3_update(structs-3); + _v3_structs/graph_update(structs-3, graph-2); + -> structs-2, graph-2 + +###### TIMELINE VERTICE ADD +egraph_vertice_add(); + id = freeids[vertices_count]; + v = vertices[id]; + v->id = id; + vertices_count++; + v->v3-new = 1; + +_v3_update(); + v->v2-new = v->v3-new; + v->v3-new = 0; + _v2_add() + v->graph2_vid = graph2_vcount; + graph2_vcount++; + igraph_add_vertices(graph2); + +_layouting_start(); + // end up in coords2 + +_layouting_end(); +_coords_copy(); + // end up in coords + +_v2_update(); + _add() + v->v2-new = 0; + v->graph_vid = graph_vcount; + graph_vcount++; + igraph_add_vertices(graph); + evas_object + +// in structs, graph, coords + +###### TIMELINE VERTICE DEL +egraph_vertice_del(); + v->v3-del = 1; + +_v3_update(); + v->v2-del = v->v3-del; + v->v3-del = 0; + _v2_del() + igraph_delete_vertices(v->graph2_vid); + graph2_vcount--; + +_layouting_start(); + // not in coords2 + +_layouting_end(); +_coords_copy(); + // not in coords + +_v2_update(); + _del(); + igraph_delete_vertices(v->graph_vid); + graph_vcount--; + freeids[vertices_count] = v->id; + vertices_count--; + free(v); + +// removed from structs, graph, coords + +###### TIMELINE VERTICE DEL + + -- cgit v1.2.3-59-g8ed1b From b8299824f037e364593690c5d744be7f42e1455b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 17:11:07 +0100 Subject: remove warning, this lib should work now --- README.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.txt b/README.txt index 1248c36..caac252 100644 --- a/README.txt +++ b/README.txt @@ -1,7 +1,5 @@ egraph - library for rendring dynamic graphs in evas -WARNING: Development in progress, don't expect this to work ! - Requirements ============ -- cgit v1.2.3-59-g8ed1b From 284bdd2f44bedbcf90a4b3c324a534734d1417cf Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 18:18:59 +0100 Subject: cleanup different layout handling code and allow for EGRAPH_LAYOUT_KAMADAKAWAI --- Egraph.h | 2 ++ egraph.c | 90 +++++++++++++++++++++++++++++++++++----------------------------- 2 files changed, 52 insertions(+), 40 deletions(-) diff --git a/Egraph.h b/Egraph.h index 4577bc8..d91ea87 100644 --- a/Egraph.h +++ b/Egraph.h @@ -12,7 +12,9 @@ typedef struct Egraph_Vertice Egraph_Vertice; typedef enum { EGRAPH_LAYOUT_GRAPHOPT = 0, + EGRAPH_LAYOUT_KAMADAKAWAI = 1, } Egraph_Layout; +#define EGRAPH_LAYOUT_DEFAULT EGRAPH_LAYOUT_GRAPHOPT struct Egraph { Evas_Object_Smart_Clipped_Data __clipped_data; diff --git a/egraph.c b/egraph.c index 5b3f250..9714f6a 100644 --- a/egraph.c +++ b/egraph.c @@ -114,7 +114,7 @@ egraph_new(Evas *evas, int directed) eg->display_vertices = 1; eg->display_names = 1; eg->display_edges = 1; - eg->layout = EGRAPH_LAYOUT_GRAPHOPT; + eg->layout = EGRAPH_LAYOUT_DEFAULT; /* needed for igraph attribute handling */ igraph_i_set_attribute_table(&igraph_cattribute_table); @@ -607,45 +607,55 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) eg = data; if (DEBUG) - printf("[-] _cb_layouting_run begin\n"); - -/* int igraph_layout_kamada_kawai(const igraph_t *graph, igraph_matrix_t *res, - igraph_integer_t niter, igraph_real_t sigma, - igraph_real_t initemp, igraph_real_t coolexp, - igraph_real_t kkconst, igraph_bool_t use_seed, - const igraph_vector_t *minx, - const igraph_vector_t *maxx, - const igraph_vector_t *miny, - const igraph_vector_t *maxy); */ -/* igraph_layout_kamada_kawai(&eg->graph2, &eg->coords2, - 1000, eg->vertices_count / 4, - 10, 0.99, - eg->vertices_count ^ 2, 1, - NULL, NULL, NULL, NULL);*/ -/* int igraph_layout_graphopt(const igraph_t *graph, igraph_matrix_t *res, - igraph_integer_t niter, - igraph_real_t node_charge, igraph_real_t node_mass, - igraph_real_t spring_length, - igraph_real_t spring_constant, - igraph_real_t max_sa_movement, - igraph_bool_t use_seed); */ -/* igraph_layout_graphopt(&eg->graph2, &eg->coords2, - 1000, - 0.001, 10, - 0, - 1, - 5, - 1); */ - niter = 50 * eg->layouting.changes_diff; - if (niter > 1000) - niter = 1000; - igraph_layout_graphopt(&eg->graph2, &eg->coords2, - niter, - 0.003, 10, - 0, - 1, - 5, - 1); + printf("[-] _cb_layouting_run begin (%d)\n", eg->layout); + + switch(eg->layout) { + case EGRAPH_LAYOUT_KAMADAKAWAI: + if (eg->layouting.changes_diff == 0) /* just a layout update */ + niter = 1000; + else + niter = 1000 * eg->layouting.changes_diff; + if (niter > 2000) + niter = 2000; + /* int igraph_layout_kamada_kawai(const igraph_t *g, igraph_matrix_t *res, + * igraph_integer_t niter, igraph_real_t sigma, + * igraph_real_t initemp, igraph_real_t coolexp, + * igraph_real_t kkconst, igraph_bool_t use_seed, + * const igraph_vector_t *minx, + * const igraph_vector_t *maxx, + * const igraph_vector_t *miny, + * const igraph_vector_t *maxy); + * Defaults from igraph doc : + * igraph_layout_kamada_kawai(&eg->graph2, &eg->coords2, + * 1000, eg->vertices_count / 4, 10, 0.99, + * eg->vertices_count ^ 2, 1, + * NULL, NULL, NULL, NULL); + */ + igraph_layout_kamada_kawai(&eg->graph2, &eg->coords2, + niter, eg->graph2_vcount, 10, 0.99, + eg->vertices_count ^ 2, 1, + NULL, NULL, NULL, NULL); + case EGRAPH_LAYOUT_GRAPHOPT: + if (eg->layouting.changes_diff == 0) /* just a layout update */ + niter = 100; + else + niter = 50 * eg->layouting.changes_diff; + if (niter > 500) + niter = 500; + /* int igraph_layout_graphopt(const igraph_t *g, igraph_matrix_t *res, + * igraph_integer_t niter, + * igraph_real_t node_charge, igraph_real_t node_mass, + * igraph_real_t spring_length, + * igraph_real_t spring_constant, + * igraph_real_t max_sa_movement, + * igraph_bool_t use_seed); + * Defaults from igraph doc : + * igraph_layout_graphopt(&eg->graph2, &eg->coords2, + * 1000, 0.001, 10, 0, 1, 5, 1); + */ + igraph_layout_graphopt(&eg->graph2, &eg->coords2, + niter, 0.003, 10, 0, 1, 5, 1); + } if (DEBUG) printf("[-] _cb_layouting_run end\n"); } -- cgit v1.2.3-59-g8ed1b From 08f02e24e0cd3d8befa9d673f0738f0b91295167 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 18:19:37 +0100 Subject: add a way to change the layout --- examples/interactive.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/examples/interactive.c b/examples/interactive.c index 2287f34..7f63a52 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -77,6 +77,24 @@ _cb_show_edges(void *data, Evas_Object *obj, void *event_info) egraph_display_edges_set(_egraph, elm_check_state_get(obj)); } +static void +cb_layout_changed(void *data, Evas_Object *obj, void *event_info) +{ + Elm_Object_Item *it; + char *selected; + int layout; + + it = event_info; + selected = elm_object_item_text_get(it); + layout = EGRAPH_LAYOUT_DEFAULT; + if (!strcmp(selected, "Kamada K.")) + layout = EGRAPH_LAYOUT_KAMADAKAWAI; + else if (!strcmp(selected, "GraphOpt")) + layout = EGRAPH_LAYOUT_GRAPHOPT; + + egraph_layout_set(_egraph, layout); +} + static void _cb_on_done(void *data, Evas_Object *obj, void *event_info) { @@ -86,7 +104,8 @@ _cb_on_done(void *data, Evas_Object *obj, void *event_info) EAPI_MAIN int elm_main(int argc, char **argv) { - Evas_Object *win, *bg, *bx, *panes, *tb, *tb_it, *ck, *egraph; + Evas_Object *win, *bg, *egraph, *panes; + Evas_Object *bx, *tb, *tb_it, *ck, *sc, *seg_it, *lb; Evas *evas; int retval = -1; @@ -151,6 +170,24 @@ elm_main(int argc, char **argv) tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", ck); elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); + lb = elm_label_add(win); + elm_object_text_set(lb, "Layout"); + evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", lb); + sc = elm_segment_control_add(win); + //evas_object_size_hint_weight_set(sc, em->weight.w, em->weight.h); + //evas_object_size_hint_align_set(sc, em->align.x, em->align.y); + seg_it = elm_segment_control_item_add(sc, NULL, "GraphOpt"); + elm_segment_control_item_selected_set(seg_it, EINA_TRUE); + seg_it = elm_segment_control_item_add(sc, NULL, "Kamada K."); + elm_segment_control_item_selected_set(seg_it, EINA_FALSE); + evas_object_smart_callback_add(sc, "changed", cb_layout_changed, NULL); + evas_object_show(sc); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", sc); + elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); elm_toolbar_item_append(tb, "exit", "Quit", _cb_on_done, NULL); elm_object_part_content_set(panes, "left", tb); -- cgit v1.2.3-59-g8ed1b From 98ef74236f4672f7320f1a7a576870363593c4f2 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 22:15:44 +0100 Subject: improve app layout --- examples/interactive.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/examples/interactive.c b/examples/interactive.c index 7f63a52..2e5a3e2 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -120,22 +120,19 @@ elm_main(int argc, char **argv) evas_object_show(bg); bx = elm_box_add(win); + elm_box_horizontal_set(bx, EINA_TRUE); evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); elm_win_resize_object_add(win, bx); evas_object_show(bx); - panes = elm_panes_add(win); - evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(panes, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_panes_content_left_size_set(panes, 0.1); - evas_object_show(panes); - tb = elm_toolbar_add(win); + elm_toolbar_homogeneous_set(tb, 0); elm_toolbar_horizontal_set(tb, EINA_FALSE); elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_MENU); - elm_toolbar_select_mode_set(tb, ELM_OBJECT_SELECT_MODE_NONE); evas_object_size_hint_weight_set(tb, 0.0, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_toolbar_select_mode_set(tb, ELM_OBJECT_SELECT_MODE_NONE); + elm_box_pack_end(bx, tb); evas_object_show(tb); elm_toolbar_item_append(tb, "object-rotate-right", "Add 1 edge", _cb_add_edge, NULL); @@ -143,7 +140,7 @@ elm_main(int argc, char **argv) _cb_add_50edges, NULL); elm_toolbar_item_append(tb, "object-rotate-right", "Add 500 edges", _cb_add_500edges, NULL); - elm_toolbar_item_append(tb, "object-rotate-right", "Delete all", + elm_toolbar_item_append(tb, "edit-delete", "Delete all", _cb_del_edges, NULL); elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); ck = elm_check_add(win); @@ -190,7 +187,13 @@ elm_main(int argc, char **argv) elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); elm_toolbar_item_append(tb, "exit", "Quit", _cb_on_done, NULL); - elm_object_part_content_set(panes, "left", tb); + + panes = elm_panes_add(win); + evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(panes, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_panes_content_right_size_set(panes, 0.0); + elm_box_pack_end(bx, panes); + evas_object_show(panes); egraph = egraph_new(evas, 1); if (!egraph) @@ -198,11 +201,17 @@ elm_main(int argc, char **argv) evas_object_size_hint_weight_set(egraph, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(egraph, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_show(egraph); - elm_object_part_content_set(panes, "right", egraph); + elm_object_part_content_set(panes, "left", egraph); - elm_box_pack_end(bx, panes); + lb = elm_label_add(win); + elm_object_text_set(lb, "Console"); + evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, 0.0); + elm_object_part_content_set(panes, "right", lb); - evas_object_resize(win, 650, 500); + evas_object_resize(win, 800, 200); // XXX workaround elm toolbar size bug + evas_object_show(win); + evas_object_resize(win, 800, 600); evas_object_show(win); _egraph = egraph; _mainwin = win; -- cgit v1.2.3-59-g8ed1b From f7d5bde5394c598f11ed60b5302bef386cb97253 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 22:23:36 +0100 Subject: raise vertice objects on draw so they appear above edges --- egraph.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/egraph.c b/egraph.c index 9714f6a..790ec6f 100644 --- a/egraph.c +++ b/egraph.c @@ -748,11 +748,13 @@ _reposition(Egraph *eg) v = eina_hash_find(eg->vertices, &id); evas_object_move(v->o, x, y); + evas_object_raise(v->o); if (v->o_text) { if (eg->display_vertices) evas_object_move(v->o_text, x+3, y+8); else evas_object_move(v->o_text, x, y); + evas_object_raise(v->o_text); } if (v->new) { if (eg->display_vertices) -- cgit v1.2.3-59-g8ed1b From 39d0585ef234dc2d2c393de31381e4c98fbd4911 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 22:26:59 +0100 Subject: yellow vertice labels --- egraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egraph.c b/egraph.c index 790ec6f..788990c 100644 --- a/egraph.c +++ b/egraph.c @@ -379,7 +379,7 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) text = evas_object_text_add(eg->evas); evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); - evas_object_color_set(text, 0, 255, 0, 255); + evas_object_color_set(text, 200, 255, 0, 255); evas_object_text_font_set(text, "Vera-Bold", VERTICE_TEXT_H); evas_object_smart_member_add(text, eg->obj); v->o_text = text; -- cgit v1.2.3-59-g8ed1b From aa7c8fb7fc9fef06cd139ceaf021a97532199dbe Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 22:27:15 +0100 Subject: black background --- examples/interactive.c | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/interactive.c b/examples/interactive.c index 2e5a3e2..879eec0 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -117,6 +117,7 @@ elm_main(int argc, char **argv) bg = elm_bg_add(win); elm_win_resize_object_add(win, bg); evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_color_set(bg, 0, 0, 0, 255); evas_object_show(bg); bx = elm_box_add(win); -- cgit v1.2.3-59-g8ed1b From 5a392c5109bb5cb41cdb1c04a9dfa8512169fe08 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 22:54:13 +0100 Subject: improve right pane --- examples/interactive.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/interactive.c b/examples/interactive.c index 879eec0..558b195 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -205,9 +205,13 @@ elm_main(int argc, char **argv) elm_object_part_content_set(panes, "left", egraph); lb = elm_label_add(win); - elm_object_text_set(lb, "Console"); - evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0); - evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, 0.0); + elm_object_style_set(lb, "marker"); + evas_object_color_set(lb, 255, 255, 255, 255); + elm_object_text_set(lb, + "Demo application for Egraph
" + "
" + "Enjoy !
"); + evas_object_show(lb); elm_object_part_content_set(panes, "right", lb); evas_object_resize(win, 800, 200); // XXX workaround elm toolbar size bug -- cgit v1.2.3-59-g8ed1b From a5f061388d141755422ef6df1f31c6a738f2ffbc Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 22:54:35 +0100 Subject: fix window title --- examples/interactive.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/interactive.c b/examples/interactive.c index 558b195..2a08121 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -111,7 +111,7 @@ elm_main(int argc, char **argv) win = elm_win_add(NULL, "panes", ELM_WIN_BASIC); evas = evas_object_evas_get(win); - elm_win_title_set(win, "Glouglou Network Mapper"); + elm_win_title_set(win, "Egraph demo app"); evas_object_smart_callback_add(win, "delete,request", _cb_on_done, NULL); bg = elm_bg_add(win); -- cgit v1.2.3-59-g8ed1b From 46bfaef32b8cb1edf1faac2b904ad2fac9a4274d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 23:16:14 +0100 Subject: add authors and license, and rename README to a more standard name --- AUTHORS | 1 + COPYING | 15 +++++++++++++++ README | 20 ++++++++++++++++++++ README.txt | 20 -------------------- 4 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 README delete mode 100644 README.txt diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..4e42cdc --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +Laurent Ghigonis diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..bae178d --- /dev/null +++ b/COPYING @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2012 Laurent Ghigonis + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ diff --git a/README b/README new file mode 100644 index 0000000..caac252 --- /dev/null +++ b/README @@ -0,0 +1,20 @@ +egraph - library for rendring dynamic graphs in evas + +Requirements +============ + +* Enlightenment Foundation Libraries +http://www.enlightenment.org + * eina + * evas + * ecore + * efx + +* igraph - http://igraph.sourceforge.net/index.html + +Installation +============ + +make +sudo make install + diff --git a/README.txt b/README.txt deleted file mode 100644 index caac252..0000000 --- a/README.txt +++ /dev/null @@ -1,20 +0,0 @@ -egraph - library for rendring dynamic graphs in evas - -Requirements -============ - -* Enlightenment Foundation Libraries -http://www.enlightenment.org - * eina - * evas - * ecore - * efx - -* igraph - http://igraph.sourceforge.net/index.html - -Installation -============ - -make -sudo make install - -- cgit v1.2.3-59-g8ed1b From bea1e14af35417ee6423dd9b166c59cd57c7796b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 8 Dec 2012 23:58:07 +0100 Subject: add History section --- README | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README b/README index caac252..f852dab 100644 --- a/README +++ b/README @@ -18,3 +18,8 @@ Installation make sudo make install +History +======= + +Egraph was developped for the Glouglou Network Map (gg_map), a tool for +live network visualisation based on the Glouglou framework. -- cgit v1.2.3-59-g8ed1b From 24516cb713a17276d0507b8280eff17a71d88f9d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 01:43:55 +0100 Subject: use efx_move for moving the nodes, and make nodes label and edges move consequently using EVAS_CALLBACK_MOVE --- Egraph.h | 2 ++ egraph.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/Egraph.h b/Egraph.h index d91ea87..357e1fc 100644 --- a/Egraph.h +++ b/Egraph.h @@ -24,6 +24,7 @@ struct Egraph { int display_vertices; int display_names; int display_edges; + int use_animations; Egraph_Layout layout; struct { Ecore_Thread *thread; @@ -48,6 +49,7 @@ struct Egraph_Vertice { char *name; Evas_Object *o; Evas_Object *o_text; + Eina_List *edges; void *data; u_int new : 1; u_int v2_new : 1; diff --git a/egraph.c b/egraph.c index 788990c..e8541a8 100644 --- a/egraph.c +++ b/egraph.c @@ -1,4 +1,5 @@ #include +#include #include "Egraph.h" @@ -32,6 +33,8 @@ static void _cb_layouting_run(void *data, Ecore_Thread *thread); static void _cb_layouting_end(void *data, Ecore_Thread *thread); static void _cb_layouting_cancel(void *data, Ecore_Thread *thread); static int _igraph_query_vid(igraph_t *g, int g_len, int id); +static void _cb_vertice_move(void *data, + Evas *evas, Evas_Object *obj, void *event_info); static void _reposition(Egraph *eg); static void _matrix_minmax_2v(const igraph_matrix_t *m, int row_count, float *c1min, float *c1max, @@ -105,6 +108,9 @@ egraph_new(Evas *evas, int directed) EINA_SAFETY_ON_NULL_RETURN_VAL(evas, NULL); + efx_init(); + eina_log_domain_level_set("efx", EINA_LOG_LEVEL_WARN); + obj = evas_object_smart_add(evas, _egraph_smart_class_new()); eg = evas_object_smart_data_get(obj); if (!eg) goto err; @@ -114,6 +120,7 @@ egraph_new(Evas *evas, int directed) eg->display_vertices = 1; eg->display_names = 1; eg->display_edges = 1; + eg->use_animations = 1; eg->layout = EGRAPH_LAYOUT_DEFAULT; /* needed for igraph attribute handling */ @@ -268,6 +275,9 @@ _edge_add(Egraph *eg, Egraph_Edge *e) evas_object_smart_member_add(eobj, eg->obj); evas_object_color_set(eobj, 255, 0, 0, 255); e->o = eobj; + + e->a->edges = eina_list_append(e->a->edges, e); + e->b->edges = eina_list_append(e->b->edges, e); } void @@ -311,6 +321,8 @@ _edge_del(Egraph *eg, Egraph_Edge *e) igraph_es_pairs_small(&es, eg->graph_directed, a_pos, b_pos, -1); igraph_delete_edges(&eg->graph, es); + e->a->edges = eina_list_remove(e->a->edges, e); + e->b->edges = eina_list_remove(e->b->edges, e); evas_object_del(e->o); eg->edges = eina_list_remove(eg->edges, e); @@ -375,6 +387,8 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) evas_object_smart_member_add(vobj, eg->obj); evas_object_color_set(vobj, 0, 0, 255, 255); evas_object_resize(vobj, VERTICE_OBJ_W, VERTICE_OBJ_H); + evas_object_event_callback_add(vobj, EVAS_CALLBACK_MOVE, _cb_vertice_move, v); + v->o = vobj; text = evas_object_text_add(eg->evas); @@ -707,17 +721,51 @@ _igraph_query_vid(igraph_t *g, int g_len, int id) return -1; } +/* Apply vertice move to it's name text object and it's edges */ static void -_reposition(Egraph *eg) +_cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) { + EGRAPH_DATA_GET(evas_object_smart_parent_get(obj), eg); Egraph_Vertice *v; Egraph_Edge *e; - Eina_List *l, *lprev; + Eina_List *l; + int x, y, w, h; + int ax, ay, bx, by; + + v = data; + evas_object_geometry_get(v->o, &x, &y, &w, &h); + + if (eg->display_names) { + evas_object_move(v->o_text, x+3, y+8); + evas_object_raise(v->o_text); + } + + EINA_LIST_FOREACH(v->edges, l, e) { + if (e->new) { + if (eg->display_edges) + evas_object_show(e->o); + e->new = 0; + } + evas_object_line_xy_get(e->o, &ax, &ay, &bx, &by); + if (e->a == v) { + ax = x + w/2; + ay = y + h/2; + } else { + bx = x + w/2; + by = y + h/2; + } + evas_object_line_xy_set(e->o, ax, ay, bx, by); + } +} + +static void +_reposition(Egraph *eg) +{ + Egraph_Vertice *v; u_int32_t id; float gw_min, gw_max, gh_min, gh_max, factor_w, factor_h; float x, y; int obj_x, obj_y, obj_w, obj_h; - int x1, x2, y1, y2, w1, w2, h1, h2; int vcur; if (DEBUG) @@ -747,36 +795,23 @@ _reposition(Egraph *eg) printf(" inobj: %6.3f %6.3f\n", x, y); v = eina_hash_find(eg->vertices, &id); - evas_object_move(v->o, x, y); + if (eg->use_animations) + efx_move(v->o, EFX_EFFECT_SPEED_DECELERATE, + &(Evas_Point){ x, y }, 1.0, NULL, NULL); + else + evas_object_move(v->o, x, y); evas_object_raise(v->o); - if (v->o_text) { - if (eg->display_vertices) - evas_object_move(v->o_text, x+3, y+8); - else - evas_object_move(v->o_text, x, y); + if (eg->display_names) { evas_object_raise(v->o_text); } if (v->new) { if (eg->display_vertices) evas_object_show(v->o); - if (v->o_text && eg->display_names) + if (eg->display_names) evas_object_show(v->o_text); v->new = 0; } } - - EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) { - if (e->v2_new || e->v3_new) - continue; - evas_object_geometry_get(e->a->o, &x1, &y1, &w1, &h1); - evas_object_geometry_get(e->b->o, &x2, &y2, &w2, &h2); - evas_object_line_xy_set(e->o, x1+w1/2, y1+h1/2, x2+w2/2, y2+h2/2); - if (e->new) { - if (eg->display_edges) - evas_object_show(e->o); - e->new = 0; - } - } } /** -- cgit v1.2.3-59-g8ed1b From 9cfd3a9171fbc8b4dfeaa45727c25fcd642cd771 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 01:50:41 +0100 Subject: add egraph_use_animations_set() to configure if Egraph should use animations --- Egraph.h | 5 +++++ egraph.c | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/Egraph.h b/Egraph.h index 357e1fc..1147270 100644 --- a/Egraph.h +++ b/Egraph.h @@ -95,6 +95,11 @@ void egraph_display_names_set(Evas_Object *obj, int set); */ void egraph_display_edges_set(Evas_Object *obj, int set); +/** + * Configure if Egraph should use animations + */ +void egraph_use_animations_set(Evas_Object *obj, int set); + /** * Adds an edge between existing vertices * diff --git a/egraph.c b/egraph.c index e8541a8..bc88125 100644 --- a/egraph.c +++ b/egraph.c @@ -220,6 +220,14 @@ egraph_display_edges_set(Evas_Object *obj, int set) } } +void +egraph_use_animations_set(Evas_Object *obj, int set) +{ + EGRAPH_DATA_GET(obj, eg); + + eg->use_animations = set; +} + Egraph_Edge * egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, void *data) -- cgit v1.2.3-59-g8ed1b From c2fbf5d715cfbc778a3cb2e0ab0e8473679cb2e8 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 01:51:07 +0100 Subject: add a checkbox to configure Egraph animations --- examples/interactive.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/interactive.c b/examples/interactive.c index 2a08121..d3be157 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -77,6 +77,12 @@ _cb_show_edges(void *data, Evas_Object *obj, void *event_info) egraph_display_edges_set(_egraph, elm_check_state_get(obj)); } +static void +_cb_use_animations(void *data, Evas_Object *obj, void *event_info) +{ + egraph_use_animations_set(_egraph, elm_check_state_get(obj)); +} + static void cb_layout_changed(void *data, Evas_Object *obj, void *event_info) { @@ -168,6 +174,14 @@ elm_main(int argc, char **argv) tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", ck); elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); + ck = elm_check_add(win); + elm_object_text_set(ck, "Use animations"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_use_animations, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); + elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); lb = elm_label_add(win); elm_object_text_set(lb, "Layout"); evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); -- cgit v1.2.3-59-g8ed1b From f5b858bb7191f34d5e1ee383a85c2a43ab2eb452 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 01:54:37 +0100 Subject: use no animations when moving / resizing --- egraph.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/egraph.c b/egraph.c index bc88125..c7a9795 100644 --- a/egraph.c +++ b/egraph.c @@ -35,7 +35,7 @@ static void _cb_layouting_cancel(void *data, Ecore_Thread *thread); static int _igraph_query_vid(igraph_t *g, int g_len, int id); static void _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info); -static void _reposition(Egraph *eg); +static void _reposition(Egraph *eg, int no_animation); static void _matrix_minmax_2v(const igraph_matrix_t *m, int row_count, float *c1min, float *c1max, float *c2min, float *c2max); @@ -86,7 +86,7 @@ _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y) { EGRAPH_DATA_GET(obj, eg); - _reposition(eg); + _reposition(eg, 1); _egraph_parent_sc->move(obj, x, y); } @@ -96,7 +96,7 @@ _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h) { EGRAPH_DATA_GET(obj, eg); - _reposition(eg); + _reposition(eg, 1); } Evas_Object * @@ -175,7 +175,7 @@ egraph_display_vertices_set(Evas_Object *obj, int set) } } - _reposition(eg); + _reposition(eg, 0); } void @@ -696,7 +696,7 @@ _cb_layouting_end(void *data, Ecore_Thread *thread) eg = data; _v2_update(eg); _coords2_copy(eg); - _reposition(eg); + _reposition(eg, 0); eg->layouting.running = 0; if (eg->layouting.todo) { eg->layouting.todo = 0; @@ -767,7 +767,7 @@ _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) } static void -_reposition(Egraph *eg) +_reposition(Egraph *eg, int no_animation) { Egraph_Vertice *v; u_int32_t id; @@ -803,7 +803,7 @@ _reposition(Egraph *eg) printf(" inobj: %6.3f %6.3f\n", x, y); v = eina_hash_find(eg->vertices, &id); - if (eg->use_animations) + if (eg->use_animations && !no_animation) efx_move(v->o, EFX_EFFECT_SPEED_DECELERATE, &(Evas_Point){ x, y }, 1.0, NULL, NULL); else -- cgit v1.2.3-59-g8ed1b From 9360c5a073b98e84b8cdba47b503fe97c7dfad60 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 02:07:43 +0100 Subject: fix positionning of vertice name when we do not display vertices --- egraph.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/egraph.c b/egraph.c index c7a9795..d82c85d 100644 --- a/egraph.c +++ b/egraph.c @@ -744,7 +744,10 @@ _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) evas_object_geometry_get(v->o, &x, &y, &w, &h); if (eg->display_names) { - evas_object_move(v->o_text, x+3, y+8); + if (eg->display_vertices) + evas_object_move(v->o_text, x+3, y+8); + else + evas_object_move(v->o_text, x, y); evas_object_raise(v->o_text); } -- cgit v1.2.3-59-g8ed1b From bb53f9720be9234edc2668abcc1f40ddb729f5c3 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 02:44:25 +0100 Subject: Add mechanism to do improvements after a change has been made to the graph --- Egraph.h | 8 ++++++++ egraph.c | 51 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/Egraph.h b/Egraph.h index 1147270..f2f44bb 100644 --- a/Egraph.h +++ b/Egraph.h @@ -15,6 +15,7 @@ typedef enum { EGRAPH_LAYOUT_KAMADAKAWAI = 1, } Egraph_Layout; #define EGRAPH_LAYOUT_DEFAULT EGRAPH_LAYOUT_GRAPHOPT +#define EGRAPH_LAYOUTING_IMPROVEMENTS 5 struct Egraph { Evas_Object_Smart_Clipped_Data __clipped_data; @@ -25,12 +26,14 @@ struct Egraph { int display_names; int display_edges; int use_animations; + int do_improvements; Egraph_Layout layout; struct { Ecore_Thread *thread; int running; int todo; int changes_diff; + int improvement; /* special pass to improve the graph layout */ } layouting; Eina_Hash *vertices; int vertices_count; @@ -100,6 +103,11 @@ void egraph_display_edges_set(Evas_Object *obj, int set); */ void egraph_use_animations_set(Evas_Object *obj, int set); +/** + * Configure if Egraph should do improvements after a graph change + */ +void egraph_do_improvements_set(Evas_Object *obj, int set); + /** * Adds an edge between existing vertices * diff --git a/egraph.c b/egraph.c index d82c85d..7508328 100644 --- a/egraph.c +++ b/egraph.c @@ -121,6 +121,7 @@ egraph_new(Evas *evas, int directed) eg->display_names = 1; eg->display_edges = 1; eg->use_animations = 1; + eg->do_improvements = 1; eg->layout = EGRAPH_LAYOUT_DEFAULT; /* needed for igraph attribute handling */ @@ -228,6 +229,14 @@ egraph_use_animations_set(Evas_Object *obj, int set) eg->use_animations = set; } +void +egraph_do_improvements_set(Evas_Object *obj, int set) +{ + EGRAPH_DATA_GET(obj, eg); + + eg->do_improvements = set; +} + Egraph_Edge * egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, void *data) @@ -633,12 +642,16 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) switch(eg->layout) { case EGRAPH_LAYOUT_KAMADAKAWAI: - if (eg->layouting.changes_diff == 0) /* just a layout update */ - niter = 1000; - else - niter = 1000 * eg->layouting.changes_diff; - if (niter > 2000) - niter = 2000; + if (eg->layouting.improvement) { + niter = 300; + } else { + if (eg->layouting.changes_diff == 0) + niter = 1000; + else + niter = 1000 * eg->layouting.changes_diff; + if (niter > 2000) + niter = 2000; + } /* int igraph_layout_kamada_kawai(const igraph_t *g, igraph_matrix_t *res, * igraph_integer_t niter, igraph_real_t sigma, * igraph_real_t initemp, igraph_real_t coolexp, @@ -658,12 +671,16 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) eg->vertices_count ^ 2, 1, NULL, NULL, NULL, NULL); case EGRAPH_LAYOUT_GRAPHOPT: - if (eg->layouting.changes_diff == 0) /* just a layout update */ - niter = 100; - else - niter = 50 * eg->layouting.changes_diff; - if (niter > 500) - niter = 500; + if (eg->layouting.improvement) { + niter = 300; + } else { + if (eg->layouting.changes_diff == 0) + niter = 100; + else + niter = 50 * eg->layouting.changes_diff; + if (niter > 500) + niter = 500; + } /* int igraph_layout_graphopt(const igraph_t *g, igraph_matrix_t *res, * igraph_integer_t niter, * igraph_real_t node_charge, igraph_real_t node_mass, @@ -700,7 +717,17 @@ _cb_layouting_end(void *data, Ecore_Thread *thread) eg->layouting.running = 0; if (eg->layouting.todo) { eg->layouting.todo = 0; + eg->layouting.improvement = 0; _layouting_schedule(eg); + } else { + if (eg->do_improvements) { + if (eg->layouting.improvement < EGRAPH_LAYOUTING_IMPROVEMENTS) { + eg->layouting.improvement++; + _layouting_schedule(eg); + } else { + eg->layouting.improvement = 0; + } + } } } -- cgit v1.2.3-59-g8ed1b From 90cf9a9d1cf73245121e3b3e605293de7ba4b656 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 02:44:52 +0100 Subject: add checkbox to configure whether or not to do improvements in the graph after changes. also remove separators between checkboxes --- examples/interactive.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/examples/interactive.c b/examples/interactive.c index d3be157..e5a61d9 100644 --- a/examples/interactive.c +++ b/examples/interactive.c @@ -83,6 +83,12 @@ _cb_use_animations(void *data, Evas_Object *obj, void *event_info) egraph_use_animations_set(_egraph, elm_check_state_get(obj)); } +static void +_cb_do_improvements(void *data, Evas_Object *obj, void *event_info) +{ + egraph_do_improvements_set(_egraph, elm_check_state_get(obj)); +} + static void cb_layout_changed(void *data, Evas_Object *obj, void *event_info) { @@ -157,7 +163,6 @@ elm_main(int argc, char **argv) evas_object_smart_callback_add(ck, "changed", _cb_show_nodes, NULL); tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", ck); - elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); ck = elm_check_add(win); elm_object_text_set(ck, "Show Label"); elm_check_state_set(ck, EINA_TRUE); @@ -165,7 +170,6 @@ elm_main(int argc, char **argv) evas_object_smart_callback_add(ck, "changed", _cb_show_labels, NULL); tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", ck); - elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); ck = elm_check_add(win); elm_object_text_set(ck, "Show Edges"); elm_check_state_set(ck, EINA_TRUE); @@ -173,7 +177,6 @@ elm_main(int argc, char **argv) evas_object_smart_callback_add(ck, "changed", _cb_show_edges, NULL); tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", ck); - elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); ck = elm_check_add(win); elm_object_text_set(ck, "Use animations"); elm_check_state_set(ck, EINA_TRUE); @@ -181,6 +184,13 @@ elm_main(int argc, char **argv) evas_object_smart_callback_add(ck, "changed", _cb_use_animations, NULL); tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", ck); + ck = elm_check_add(win); + elm_object_text_set(ck, "Do improvements"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_do_improvements, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); lb = elm_label_add(win); elm_object_text_set(lb, "Layout"); -- cgit v1.2.3-59-g8ed1b From 532c1cbe5439a1cafaec8c9397566d5020e93c2f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 02:47:40 +0100 Subject: BUG++ --- doc/TODO.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/TODO.txt b/doc/TODO.txt index 5b59c03..6480a4e 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -5,6 +5,9 @@ TODO a new edge attaches to the wrong new vertice it seems to be always the same node numbers that gets this wrong edge +* BUG: vertices / vertices text fight for being on top. use evas layers ? +add 500 edges to reproduce, and watch the nodes + * find a better storage type for vertices quick access O(1) -> table possibility to foreach and remove at the same time -- cgit v1.2.3-59-g8ed1b From e72ac1da55f7837ec66f53dcfa2e810a7d3e0a33 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 02:51:53 +0100 Subject: better naming --- examples/demoapp.c | 255 +++++++++++++++++++++++++++++++++++++++++++++++++ examples/demograph.c | 59 ------------ examples/interactive.c | 255 ------------------------------------------------- examples/simplegraph.c | 59 ++++++++++++ 4 files changed, 314 insertions(+), 314 deletions(-) create mode 100644 examples/demoapp.c delete mode 100644 examples/demograph.c delete mode 100644 examples/interactive.c create mode 100644 examples/simplegraph.c diff --git a/examples/demoapp.c b/examples/demoapp.c new file mode 100644 index 0000000..e5a61d9 --- /dev/null +++ b/examples/demoapp.c @@ -0,0 +1,255 @@ +#include + +#include +#include + +Evas_Object *_mainwin, *_egraph; +Eina_List *_vertice_list = NULL; + +static void +_cb_add_edge(void *data, Evas_Object *obj, void *event_info) +{ + Egraph_Vertice *a, *b; + int ran, count; + char buf[64]; + + count = eina_list_count(_vertice_list); + if (count == 0) { + a = egraph_vertice_add(_egraph, "first", NULL); + _vertice_list = eina_list_append(_vertice_list, a); + } else { + ran = random() % count; + a = eina_list_nth(_vertice_list, ran); + } + b = egraph_vertice_add(_egraph, NULL, NULL); + snprintf(buf, sizeof(buf), "%d", b->id); + egraph_vertice_rename(_egraph, b, buf); + _vertice_list = eina_list_append(_vertice_list, b); + + egraph_edge_add(_egraph, a, b, NULL); +} + +static void +_cb_add_50edges(void *data, Evas_Object *obj, void *event_info) +{ + int i; + + for (i=0; i<50; i++) + _cb_add_edge(data, obj, event_info); +} + +static void +_cb_add_500edges(void *data, Evas_Object *obj, void *event_info) +{ + int i; + + for (i=0; i<500; i++) + _cb_add_edge(data, obj, event_info); +} + +static void +_cb_del_edges(void *data, Evas_Object *obj, void *event_info) +{ + Eina_List *l; + Egraph_Vertice *v; + + EINA_LIST_FOREACH(_vertice_list, l, v) + egraph_vertice_del(_egraph, v); + + _vertice_list = eina_list_free(_vertice_list); +} + +static void +_cb_show_nodes(void *data, Evas_Object *obj, void *event_info) +{ + egraph_display_vertices_set(_egraph, elm_check_state_get(obj)); +} + +static void +_cb_show_labels(void *data, Evas_Object *obj, void *event_info) +{ + egraph_display_names_set(_egraph, elm_check_state_get(obj)); +} + +static void +_cb_show_edges(void *data, Evas_Object *obj, void *event_info) +{ + egraph_display_edges_set(_egraph, elm_check_state_get(obj)); +} + +static void +_cb_use_animations(void *data, Evas_Object *obj, void *event_info) +{ + egraph_use_animations_set(_egraph, elm_check_state_get(obj)); +} + +static void +_cb_do_improvements(void *data, Evas_Object *obj, void *event_info) +{ + egraph_do_improvements_set(_egraph, elm_check_state_get(obj)); +} + +static void +cb_layout_changed(void *data, Evas_Object *obj, void *event_info) +{ + Elm_Object_Item *it; + char *selected; + int layout; + + it = event_info; + selected = elm_object_item_text_get(it); + layout = EGRAPH_LAYOUT_DEFAULT; + if (!strcmp(selected, "Kamada K.")) + layout = EGRAPH_LAYOUT_KAMADAKAWAI; + else if (!strcmp(selected, "GraphOpt")) + layout = EGRAPH_LAYOUT_GRAPHOPT; + + egraph_layout_set(_egraph, layout); +} + +static void +_cb_on_done(void *data, Evas_Object *obj, void *event_info) +{ + elm_exit(); +} + +EAPI_MAIN int +elm_main(int argc, char **argv) +{ + Evas_Object *win, *bg, *egraph, *panes; + Evas_Object *bx, *tb, *tb_it, *ck, *sc, *seg_it, *lb; + Evas *evas; + int retval = -1; + + win = elm_win_add(NULL, "panes", ELM_WIN_BASIC); + evas = evas_object_evas_get(win); + elm_win_title_set(win, "Egraph demo app"); + evas_object_smart_callback_add(win, "delete,request", _cb_on_done, NULL); + + bg = elm_bg_add(win); + elm_win_resize_object_add(win, bg); + evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_color_set(bg, 0, 0, 0, 255); + evas_object_show(bg); + + bx = elm_box_add(win); + elm_box_horizontal_set(bx, EINA_TRUE); + evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_win_resize_object_add(win, bx); + evas_object_show(bx); + + tb = elm_toolbar_add(win); + elm_toolbar_homogeneous_set(tb, 0); + elm_toolbar_horizontal_set(tb, EINA_FALSE); + elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_MENU); + evas_object_size_hint_weight_set(tb, 0.0, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_toolbar_select_mode_set(tb, ELM_OBJECT_SELECT_MODE_NONE); + elm_box_pack_end(bx, tb); + evas_object_show(tb); + elm_toolbar_item_append(tb, "object-rotate-right", "Add 1 edge", + _cb_add_edge, NULL); + elm_toolbar_item_append(tb, "object-rotate-right", "Add 50 edges", + _cb_add_50edges, NULL); + elm_toolbar_item_append(tb, "object-rotate-right", "Add 500 edges", + _cb_add_500edges, NULL); + elm_toolbar_item_append(tb, "edit-delete", "Delete all", + _cb_del_edges, NULL); + elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); + ck = elm_check_add(win); + elm_object_text_set(ck, "Show Node"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_show_nodes, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); + ck = elm_check_add(win); + elm_object_text_set(ck, "Show Label"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_show_labels, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); + ck = elm_check_add(win); + elm_object_text_set(ck, "Show Edges"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_show_edges, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); + ck = elm_check_add(win); + elm_object_text_set(ck, "Use animations"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_use_animations, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); + ck = elm_check_add(win); + elm_object_text_set(ck, "Do improvements"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_do_improvements, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); + elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); + lb = elm_label_add(win); + elm_object_text_set(lb, "Layout"); + evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", lb); + sc = elm_segment_control_add(win); + //evas_object_size_hint_weight_set(sc, em->weight.w, em->weight.h); + //evas_object_size_hint_align_set(sc, em->align.x, em->align.y); + seg_it = elm_segment_control_item_add(sc, NULL, "GraphOpt"); + elm_segment_control_item_selected_set(seg_it, EINA_TRUE); + seg_it = elm_segment_control_item_add(sc, NULL, "Kamada K."); + elm_segment_control_item_selected_set(seg_it, EINA_FALSE); + evas_object_smart_callback_add(sc, "changed", cb_layout_changed, NULL); + evas_object_show(sc); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", sc); + elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); + elm_toolbar_item_append(tb, "exit", "Quit", + _cb_on_done, NULL); + + panes = elm_panes_add(win); + evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(panes, EVAS_HINT_FILL, EVAS_HINT_FILL); + elm_panes_content_right_size_set(panes, 0.0); + elm_box_pack_end(bx, panes); + evas_object_show(panes); + + egraph = egraph_new(evas, 1); + if (!egraph) + goto quit; + evas_object_size_hint_weight_set(egraph, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(egraph, EVAS_HINT_FILL, EVAS_HINT_FILL); + evas_object_show(egraph); + elm_object_part_content_set(panes, "left", egraph); + + lb = elm_label_add(win); + elm_object_style_set(lb, "marker"); + evas_object_color_set(lb, 255, 255, 255, 255); + elm_object_text_set(lb, + "Demo application for Egraph
" + "
" + "Enjoy !
"); + evas_object_show(lb); + elm_object_part_content_set(panes, "right", lb); + + evas_object_resize(win, 800, 200); // XXX workaround elm toolbar size bug + evas_object_show(win); + evas_object_resize(win, 800, 600); + evas_object_show(win); + _egraph = egraph; + _mainwin = win; + + elm_run(); + retval = 0; + +quit: + elm_shutdown(); + return retval; +} +ELM_MAIN() diff --git a/examples/demograph.c b/examples/demograph.c deleted file mode 100644 index 43e6d59..0000000 --- a/examples/demograph.c +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#include -#include - -#include "../Egraph.h" - -Evas_Object *_egraph_obj = NULL; - -static void -_on_destroy(Ecore_Evas *ee) -{ - ecore_main_loop_quit(); -} - -static void -_canvas_resize_cb(Ecore_Evas *ee) -{ - int w, h; - - printf("_canvas_resize_cb\n"); - ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); - evas_object_resize(_egraph_obj, w, h); -} - -int -main(void) -{ - Ecore_Evas *ee; - Evas *evas; - Egraph_Vertice *a, *b; - Egraph_Edge *e; - - if (!ecore_evas_init()) - return EXIT_FAILURE; - ee = ecore_evas_new(NULL, 10, 10, 100, 100, NULL); - if (!ee) - return -1; - ecore_evas_callback_destroy_set(ee, _on_destroy); - ecore_evas_callback_resize_set(ee, _canvas_resize_cb); - ecore_evas_show(ee); - evas = ecore_evas_get(ee); - - _egraph_obj = egraph_new(evas, 1); - evas_object_resize(_egraph_obj, 100, 100); - evas_object_show(_egraph_obj); - - a = egraph_vertice_add(_egraph_obj, "a", NULL); - b = egraph_vertice_add(_egraph_obj, "b", NULL); - e = egraph_edge_add(_egraph_obj, a, b, NULL); - - ecore_main_loop_begin(); - - evas_object_del(_egraph_obj); - ecore_evas_free(ee); - ecore_evas_shutdown(); - - return (!_egraph_obj); -} diff --git a/examples/interactive.c b/examples/interactive.c deleted file mode 100644 index e5a61d9..0000000 --- a/examples/interactive.c +++ /dev/null @@ -1,255 +0,0 @@ -#include - -#include -#include - -Evas_Object *_mainwin, *_egraph; -Eina_List *_vertice_list = NULL; - -static void -_cb_add_edge(void *data, Evas_Object *obj, void *event_info) -{ - Egraph_Vertice *a, *b; - int ran, count; - char buf[64]; - - count = eina_list_count(_vertice_list); - if (count == 0) { - a = egraph_vertice_add(_egraph, "first", NULL); - _vertice_list = eina_list_append(_vertice_list, a); - } else { - ran = random() % count; - a = eina_list_nth(_vertice_list, ran); - } - b = egraph_vertice_add(_egraph, NULL, NULL); - snprintf(buf, sizeof(buf), "%d", b->id); - egraph_vertice_rename(_egraph, b, buf); - _vertice_list = eina_list_append(_vertice_list, b); - - egraph_edge_add(_egraph, a, b, NULL); -} - -static void -_cb_add_50edges(void *data, Evas_Object *obj, void *event_info) -{ - int i; - - for (i=0; i<50; i++) - _cb_add_edge(data, obj, event_info); -} - -static void -_cb_add_500edges(void *data, Evas_Object *obj, void *event_info) -{ - int i; - - for (i=0; i<500; i++) - _cb_add_edge(data, obj, event_info); -} - -static void -_cb_del_edges(void *data, Evas_Object *obj, void *event_info) -{ - Eina_List *l; - Egraph_Vertice *v; - - EINA_LIST_FOREACH(_vertice_list, l, v) - egraph_vertice_del(_egraph, v); - - _vertice_list = eina_list_free(_vertice_list); -} - -static void -_cb_show_nodes(void *data, Evas_Object *obj, void *event_info) -{ - egraph_display_vertices_set(_egraph, elm_check_state_get(obj)); -} - -static void -_cb_show_labels(void *data, Evas_Object *obj, void *event_info) -{ - egraph_display_names_set(_egraph, elm_check_state_get(obj)); -} - -static void -_cb_show_edges(void *data, Evas_Object *obj, void *event_info) -{ - egraph_display_edges_set(_egraph, elm_check_state_get(obj)); -} - -static void -_cb_use_animations(void *data, Evas_Object *obj, void *event_info) -{ - egraph_use_animations_set(_egraph, elm_check_state_get(obj)); -} - -static void -_cb_do_improvements(void *data, Evas_Object *obj, void *event_info) -{ - egraph_do_improvements_set(_egraph, elm_check_state_get(obj)); -} - -static void -cb_layout_changed(void *data, Evas_Object *obj, void *event_info) -{ - Elm_Object_Item *it; - char *selected; - int layout; - - it = event_info; - selected = elm_object_item_text_get(it); - layout = EGRAPH_LAYOUT_DEFAULT; - if (!strcmp(selected, "Kamada K.")) - layout = EGRAPH_LAYOUT_KAMADAKAWAI; - else if (!strcmp(selected, "GraphOpt")) - layout = EGRAPH_LAYOUT_GRAPHOPT; - - egraph_layout_set(_egraph, layout); -} - -static void -_cb_on_done(void *data, Evas_Object *obj, void *event_info) -{ - elm_exit(); -} - -EAPI_MAIN int -elm_main(int argc, char **argv) -{ - Evas_Object *win, *bg, *egraph, *panes; - Evas_Object *bx, *tb, *tb_it, *ck, *sc, *seg_it, *lb; - Evas *evas; - int retval = -1; - - win = elm_win_add(NULL, "panes", ELM_WIN_BASIC); - evas = evas_object_evas_get(win); - elm_win_title_set(win, "Egraph demo app"); - evas_object_smart_callback_add(win, "delete,request", _cb_on_done, NULL); - - bg = elm_bg_add(win); - elm_win_resize_object_add(win, bg); - evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_color_set(bg, 0, 0, 0, 255); - evas_object_show(bg); - - bx = elm_box_add(win); - elm_box_horizontal_set(bx, EINA_TRUE); - evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - elm_win_resize_object_add(win, bx); - evas_object_show(bx); - - tb = elm_toolbar_add(win); - elm_toolbar_homogeneous_set(tb, 0); - elm_toolbar_horizontal_set(tb, EINA_FALSE); - elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_MENU); - evas_object_size_hint_weight_set(tb, 0.0, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_toolbar_select_mode_set(tb, ELM_OBJECT_SELECT_MODE_NONE); - elm_box_pack_end(bx, tb); - evas_object_show(tb); - elm_toolbar_item_append(tb, "object-rotate-right", "Add 1 edge", - _cb_add_edge, NULL); - elm_toolbar_item_append(tb, "object-rotate-right", "Add 50 edges", - _cb_add_50edges, NULL); - elm_toolbar_item_append(tb, "object-rotate-right", "Add 500 edges", - _cb_add_500edges, NULL); - elm_toolbar_item_append(tb, "edit-delete", "Delete all", - _cb_del_edges, NULL); - elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); - ck = elm_check_add(win); - elm_object_text_set(ck, "Show Node"); - elm_check_state_set(ck, EINA_TRUE); - evas_object_show(ck); - evas_object_smart_callback_add(ck, "changed", _cb_show_nodes, NULL); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_object_item_part_content_set(tb_it, "object", ck); - ck = elm_check_add(win); - elm_object_text_set(ck, "Show Label"); - elm_check_state_set(ck, EINA_TRUE); - evas_object_show(ck); - evas_object_smart_callback_add(ck, "changed", _cb_show_labels, NULL); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_object_item_part_content_set(tb_it, "object", ck); - ck = elm_check_add(win); - elm_object_text_set(ck, "Show Edges"); - elm_check_state_set(ck, EINA_TRUE); - evas_object_show(ck); - evas_object_smart_callback_add(ck, "changed", _cb_show_edges, NULL); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_object_item_part_content_set(tb_it, "object", ck); - ck = elm_check_add(win); - elm_object_text_set(ck, "Use animations"); - elm_check_state_set(ck, EINA_TRUE); - evas_object_show(ck); - evas_object_smart_callback_add(ck, "changed", _cb_use_animations, NULL); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_object_item_part_content_set(tb_it, "object", ck); - ck = elm_check_add(win); - elm_object_text_set(ck, "Do improvements"); - elm_check_state_set(ck, EINA_TRUE); - evas_object_show(ck); - evas_object_smart_callback_add(ck, "changed", _cb_do_improvements, NULL); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_object_item_part_content_set(tb_it, "object", ck); - elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); - lb = elm_label_add(win); - elm_object_text_set(lb, "Layout"); - evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_object_item_part_content_set(tb_it, "object", lb); - sc = elm_segment_control_add(win); - //evas_object_size_hint_weight_set(sc, em->weight.w, em->weight.h); - //evas_object_size_hint_align_set(sc, em->align.x, em->align.y); - seg_it = elm_segment_control_item_add(sc, NULL, "GraphOpt"); - elm_segment_control_item_selected_set(seg_it, EINA_TRUE); - seg_it = elm_segment_control_item_add(sc, NULL, "Kamada K."); - elm_segment_control_item_selected_set(seg_it, EINA_FALSE); - evas_object_smart_callback_add(sc, "changed", cb_layout_changed, NULL); - evas_object_show(sc); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_object_item_part_content_set(tb_it, "object", sc); - elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); - elm_toolbar_item_append(tb, "exit", "Quit", - _cb_on_done, NULL); - - panes = elm_panes_add(win); - evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(panes, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_panes_content_right_size_set(panes, 0.0); - elm_box_pack_end(bx, panes); - evas_object_show(panes); - - egraph = egraph_new(evas, 1); - if (!egraph) - goto quit; - evas_object_size_hint_weight_set(egraph, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(egraph, EVAS_HINT_FILL, EVAS_HINT_FILL); - evas_object_show(egraph); - elm_object_part_content_set(panes, "left", egraph); - - lb = elm_label_add(win); - elm_object_style_set(lb, "marker"); - evas_object_color_set(lb, 255, 255, 255, 255); - elm_object_text_set(lb, - "Demo application for Egraph
" - "
" - "Enjoy !
"); - evas_object_show(lb); - elm_object_part_content_set(panes, "right", lb); - - evas_object_resize(win, 800, 200); // XXX workaround elm toolbar size bug - evas_object_show(win); - evas_object_resize(win, 800, 600); - evas_object_show(win); - _egraph = egraph; - _mainwin = win; - - elm_run(); - retval = 0; - -quit: - elm_shutdown(); - return retval; -} -ELM_MAIN() diff --git a/examples/simplegraph.c b/examples/simplegraph.c new file mode 100644 index 0000000..43e6d59 --- /dev/null +++ b/examples/simplegraph.c @@ -0,0 +1,59 @@ +#include +#include +#include +#include + +#include "../Egraph.h" + +Evas_Object *_egraph_obj = NULL; + +static void +_on_destroy(Ecore_Evas *ee) +{ + ecore_main_loop_quit(); +} + +static void +_canvas_resize_cb(Ecore_Evas *ee) +{ + int w, h; + + printf("_canvas_resize_cb\n"); + ecore_evas_geometry_get(ee, NULL, NULL, &w, &h); + evas_object_resize(_egraph_obj, w, h); +} + +int +main(void) +{ + Ecore_Evas *ee; + Evas *evas; + Egraph_Vertice *a, *b; + Egraph_Edge *e; + + if (!ecore_evas_init()) + return EXIT_FAILURE; + ee = ecore_evas_new(NULL, 10, 10, 100, 100, NULL); + if (!ee) + return -1; + ecore_evas_callback_destroy_set(ee, _on_destroy); + ecore_evas_callback_resize_set(ee, _canvas_resize_cb); + ecore_evas_show(ee); + evas = ecore_evas_get(ee); + + _egraph_obj = egraph_new(evas, 1); + evas_object_resize(_egraph_obj, 100, 100); + evas_object_show(_egraph_obj); + + a = egraph_vertice_add(_egraph_obj, "a", NULL); + b = egraph_vertice_add(_egraph_obj, "b", NULL); + e = egraph_edge_add(_egraph_obj, a, b, NULL); + + ecore_main_loop_begin(); + + evas_object_del(_egraph_obj); + ecore_evas_free(ee); + ecore_evas_shutdown(); + + return (!_egraph_obj); +} -- cgit v1.2.3-59-g8ed1b From a1668faf17ecc5c1bba3ad4b57f13c7f1716d24c Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 02:52:00 +0100 Subject: present the demoapp --- README | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README b/README index f852dab..e2cedf7 100644 --- a/README +++ b/README @@ -18,6 +18,13 @@ Installation make sudo make install +You can run the demoapp in examples : +make -C examples +./examples/demoapp + +You can use OpenGL rendering : +ELM_ENGINE=opengl_x11 ./examples/demoapp + History ======= -- cgit v1.2.3-59-g8ed1b From 57f28e00976f2b4de3af119f241d0b54d7af25b5 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 02:53:47 +0100 Subject: add my hand notes --- doc/egraph.xoj | Bin 0 -> 105411 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 doc/egraph.xoj diff --git a/doc/egraph.xoj b/doc/egraph.xoj new file mode 100644 index 0000000..59ca038 Binary files /dev/null and b/doc/egraph.xoj differ -- cgit v1.2.3-59-g8ed1b From 68b4235b7993bcc3e0c29aca84ebe0334f8a3004 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 04:31:02 +0100 Subject: update igraph Requirements --- README | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README b/README index e2cedf7..671cdf8 100644 --- a/README +++ b/README @@ -10,7 +10,12 @@ http://www.enlightenment.org * ecore * efx -* igraph - http://igraph.sourceforge.net/index.html +* igraph v0.6 +http://igraph.sourceforge.net/index.html + * for Ubuntu: v0.6 is *not* available in ubuntu packages +You can download it here : +http://sourceforge.net/projects/igraph/files/C%20library/0.6/igraph-0.6.tar.gz/download + * for Archlinux: yaourt -S igraph Installation ============ -- cgit v1.2.3-59-g8ed1b From 50cf7c054af42c0ba0059ea955edda48276b629e Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 04:54:41 +0100 Subject: ideas from raster --- doc/TODO.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/doc/TODO.txt b/doc/TODO.txt index 6480a4e..0d8fc28 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -8,6 +8,11 @@ it seems to be always the same node numbers that gets this wrong edge * BUG: vertices / vertices text fight for being on top. use evas layers ? add 500 edges to reproduce, and watch the nodes +* speed: evas_object_rectangles +04:40 <@raster> they add clipoouts +04:41 <@raster> make them just a bit translucent +04:41 <@raster> and it'll be faster + * find a better storage type for vertices quick access O(1) -> table possibility to foreach and remove at the same time @@ -24,3 +29,20 @@ egraph_vertice_add(Egraph *eg, const char *name, void *data); egraph_edge_add(Egraph *eg, const char *a, const char *b, void *data); +* speed: draw directly to a surface and map to evas via invisible polygons +see elementary/src/bin/test_gesture_layer3.c +04:45 < glouglou> i would like to draw directly in a surface and then give it to evas, but i want in the future to have user interaction with the nodes of my + graph, like click click reaction, so i guess i cannot escape from creating one evas object for each node and edge +04:46 <@raster> trick: +04:47 <@raster> u can just create invisible rects +04:47 < glouglou> (i can imagine crazy mapping of the clicks on my surface that triggers evas callbacks, but i'm not that crazy) +04:47 <@raster> and overlay them on your image +04:47 <@raster> use them for event stuff +04:47 < glouglou> lol +04:47 <@raster> or polygons tyoo +04:47 <@raster> thats about the only use of polygons +04:47 <@raster> as u can do exact inside/outside poly checks for events +04:48 < glouglou> i think you are talking about the crazy things i don't want to do :p +04:48 <@raster> one of the elm demos does this +04:48 <@raster> for soming/rotating with little photos +04:48 <@raster> multitouch test stuff -- cgit v1.2.3-59-g8ed1b From 6bdd0b8885145c1e2617203d8ec322e29339ef26 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 19:01:56 +0100 Subject: TODO++ from ludivina and BUG++ --- doc/TODO.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/TODO.txt b/doc/TODO.txt index 0d8fc28..b50f2a4 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -1,6 +1,11 @@ TODO ==== +* zoom + +* BUG: show nodes labels does not show old nodes labels +reproduce: do not show labels, add edges, show label, add edges + * BUG: sometimes when you add nodes during layouting, the graph is broken a new edge attaches to the wrong new vertice it seems to be always the same node numbers that gets this wrong edge -- cgit v1.2.3-59-g8ed1b From 314565713bf5db93aa70a54d33f0085722590ab5 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 19:03:19 +0100 Subject: add description of evas bug --- doc/bug_lockup_evas.txt | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 doc/bug_lockup_evas.txt diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt new file mode 100644 index 0000000..2a57b6e --- /dev/null +++ b/doc/bug_lockup_evas.txt @@ -0,0 +1,38 @@ +=============================================================================== +2012-12-09_18-10 + +ELM_ENGINE=opengl_x11 gdb ./examples/demoapp +run + +// use the app, and it locks up during an animation +// Ctrl-C + +(gdb) bt +#0 0x00007ffff7233fe6 in _calc_intra_outer_rect_area (outer=, intra=, a=..., b=...) at lib/evas/common/evas_tiler.c:468 +#1 rect_list_add_split_fuzzy (node=0x1967160, rects=0xdf91a8, accepted_error=) at lib/evas/common/evas_tiler.c:652 +#2 rect_list_add_split_fuzzy_and_merge (node=0x1967160, rects=0xdf91a8, split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#3 _add_redraw (h=16, w=24, y=200, x=882, rects=0xdf91a8) at lib/evas/common/evas_tiler.c:956 +#4 evas_common_tilebuf_add_redraw (tb=0xdf9170, x=882, y=200, w=24, h=16) at lib/evas/common/evas_tiler.c:986 +#5 0x00007ffff71b2af2 in evas_object_render_pre_effect_updates (rects=0x68ad48, eo_obj=, is_v=1, was_v=) + at lib/evas/canvas/evas_object_main.c:343 +#6 0x00007ffff71f1bfc in _evas_render_phase1_direct (render_objects=0x1498d30, active_objects=0x68ab50, e=, restack_objects=, + delete_objects=) at lib/evas/canvas/evas_render.c:231 +#7 evas_render_updates_internal (eo_e=0x68aac0, make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') at lib/evas/canvas/evas_render.c:1357 +#8 0x00007ffff71f3cd7 in _canvas_render_updates (eo_e=, _pd=, list=) at lib/evas/canvas/evas_render.c:1795 +#9 0x00007ffff6acba35 in _eo_op_internal (obj=0x68aac0, op_type=EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe1b8) at lib/eo/eo.c:363 +#10 0x00007ffff6acd6cd in _eo_dov_internal (p_list=0x7fffffffe1b8, op_type=EO_OP_TYPE_REGULAR, obj=0x68aac0) at lib/eo/eo.c:403 +#11 eo_do_internal (obj=0x68aac0, op_type=op_type@entry=EO_OP_TYPE_REGULAR) at lib/eo/eo.c:434 +#12 0x00007ffff71f3c5f in evas_render_updates (eo_e=) at lib/evas/canvas/evas_render.c:1779 +#13 0x00007fffe73da43a in _ecore_evas_x_render (ee=0x6892f0) at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#14 0x00007ffff68ba7f1 in _ecore_evas_idle_enter (data=) at lib/ecore_evas/ecore_evas.c:59 +#15 0x00007ffff6f3c019 in _ecore_call_task_cb (data=, func=) at lib/ecore/ecore_private.h:300 +#16 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#17 0x00007ffff6f3e47b in _ecore_main_loop_iterate_internal (once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#18 0x00007ffff6f3eb27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 +#19 0x00000000004027bf in elm_main (argc=1, argv=0x7fffffffe568) at demoapp.c:248 +#20 0x0000000000402804 in main (argc=1, argv=0x7fffffffe568) at demoapp.c:255 + +=============================================================================== + + -- cgit v1.2.3-59-g8ed1b From a4d7943ab56c64e0eeeb76fabb4a4f782b9a084e Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 19:06:27 +0100 Subject: add Thanks section --- README | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README b/README index 671cdf8..f82901b 100644 --- a/README +++ b/README @@ -30,6 +30,13 @@ make -C examples You can use OpenGL rendering : ELM_ENGINE=opengl_x11 ./examples/demoapp +Thanks +====== + +Thanks to ntamas (http://sixdegrees.hu/) for her advices on igraph. +Thanks to raster for tech advices on evas / elementary. +Thanks to ludivina for graphical advices. + History ======= -- cgit v1.2.3-59-g8ed1b From 9aaf8b4915a1bd3f21a1b2db67ce56c54bc92ee2 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 19:50:00 +0100 Subject: improve app layout --- examples/demoapp.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/examples/demoapp.c b/examples/demoapp.c index e5a61d9..3e82b8a 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -139,12 +139,13 @@ elm_main(int argc, char **argv) evas_object_show(bx); tb = elm_toolbar_add(win); - elm_toolbar_homogeneous_set(tb, 0); + elm_toolbar_homogeneous_set(tb, EINA_FALSE); elm_toolbar_horizontal_set(tb, EINA_FALSE); elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_MENU); + elm_toolbar_transverse_expanded_set(tb, EINA_TRUE); + elm_object_style_set(tb, "item_centered"); evas_object_size_hint_weight_set(tb, 0.0, EVAS_HINT_EXPAND); evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL); - elm_toolbar_select_mode_set(tb, ELM_OBJECT_SELECT_MODE_NONE); elm_box_pack_end(bx, tb); evas_object_show(tb); elm_toolbar_item_append(tb, "object-rotate-right", "Add 1 edge", @@ -156,6 +157,24 @@ elm_main(int argc, char **argv) elm_toolbar_item_append(tb, "edit-delete", "Delete all", _cb_del_edges, NULL); elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); + lb = elm_label_add(win); + elm_object_text_set(lb, "Layout"); + evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", lb); + sc = elm_segment_control_add(win); + //evas_object_size_hint_weight_set(sc, em->weight.w, em->weight.h); + //evas_object_size_hint_align_set(sc, em->align.x, em->align.y); + seg_it = elm_segment_control_item_add(sc, NULL, "GraphOpt"); + elm_segment_control_item_selected_set(seg_it, EINA_TRUE); + seg_it = elm_segment_control_item_add(sc, NULL, "Kamada K."); + elm_segment_control_item_selected_set(seg_it, EINA_FALSE); + evas_object_smart_callback_add(sc, "changed", cb_layout_changed, NULL); + evas_object_show(sc); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", sc); + //elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); ck = elm_check_add(win); elm_object_text_set(ck, "Show Node"); elm_check_state_set(ck, EINA_TRUE); @@ -191,25 +210,7 @@ elm_main(int argc, char **argv) evas_object_smart_callback_add(ck, "changed", _cb_do_improvements, NULL); tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", ck); - elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); - lb = elm_label_add(win); - elm_object_text_set(lb, "Layout"); - evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); - evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_object_item_part_content_set(tb_it, "object", lb); - sc = elm_segment_control_add(win); - //evas_object_size_hint_weight_set(sc, em->weight.w, em->weight.h); - //evas_object_size_hint_align_set(sc, em->align.x, em->align.y); - seg_it = elm_segment_control_item_add(sc, NULL, "GraphOpt"); - elm_segment_control_item_selected_set(seg_it, EINA_TRUE); - seg_it = elm_segment_control_item_add(sc, NULL, "Kamada K."); - elm_segment_control_item_selected_set(seg_it, EINA_FALSE); - evas_object_smart_callback_add(sc, "changed", cb_layout_changed, NULL); - evas_object_show(sc); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_object_item_part_content_set(tb_it, "object", sc); - elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); + //elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); elm_toolbar_item_append(tb, "exit", "Quit", _cb_on_done, NULL); @@ -238,9 +239,9 @@ elm_main(int argc, char **argv) evas_object_show(lb); elm_object_part_content_set(panes, "right", lb); - evas_object_resize(win, 800, 200); // XXX workaround elm toolbar size bug + evas_object_resize(win, 150, 150); evas_object_show(win); - evas_object_resize(win, 800, 600); + evas_object_resize(win, 850, 600); evas_object_show(win); _egraph = egraph; _mainwin = win; -- cgit v1.2.3-59-g8ed1b From 575e088979962663aeebf20078fa7cfdcfb963a7 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 9 Dec 2012 23:32:07 +0100 Subject: if gg_packet type is not about packets, do not inject pattern --- src/elife_evas_smart.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/elife_evas_smart.c b/src/elife_evas_smart.c index f14e534..acbd9a2 100644 --- a/src/elife_evas_smart.c +++ b/src/elife_evas_smart.c @@ -161,7 +161,7 @@ gg_packet(struct gg_client *cli, struct gg_packet *pkt) case PACKET_FORK: color=0xff0000; break; case PACKET_EXEC: color=0x00ff00; break; case PACKET_EXIT: color=0x0000ff; break; - default: color=0x0f00f0; break; + default: return 0; } grid_inject_pattern(grid, color); -- cgit v1.2.3-59-g8ed1b From 75b11941cf69f62d8f287b420eaf21842b4bafa9 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 00:27:23 +0100 Subject: add egraph_edge_find() to find an edge by its vertices --- Egraph.h | 6 ++++++ egraph.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/Egraph.h b/Egraph.h index f2f44bb..1aaedac 100644 --- a/Egraph.h +++ b/Egraph.h @@ -127,6 +127,12 @@ Egraph_Edge *egraph_edge_add(Evas_Object *obj, */ void egraph_edge_del(Evas_Object *obj, Egraph_Edge *e); +/** + * Finds if an edge exists between 2 vertices + */ +Egraph_Edge *egraph_edge_find(Evas_Object *obj, + Egraph_Vertice *a, Egraph_Vertice *b); + /** * Add a vertice to the graph * diff --git a/egraph.c b/egraph.c index 7508328..0ad5539 100644 --- a/egraph.c +++ b/egraph.c @@ -346,6 +346,20 @@ _edge_del(Egraph *eg, Egraph_Edge *e) free(e); } +Egraph_Edge * +egraph_edge_find(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b) +{ + EGRAPH_DATA_GET(obj, eg); + Egraph_Edge *e; + Eina_List *l; + + EINA_LIST_FOREACH(eg->edges, l, e) + if ((e->a == a && e->b == b) || + (e->a == b && e->b == a)) + return e; + return NULL; +} + Egraph_Vertice * egraph_vertice_add(Evas_Object *obj, const char *name, void *data) { -- cgit v1.2.3-59-g8ed1b From 2f8e2da9edb8f48e55f6079fdbcab9d9588934c5 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 00:28:32 +0100 Subject: add links to igraph documentation for layouts --- egraph.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/egraph.c b/egraph.c index 0ad5539..ea2f5ba 100644 --- a/egraph.c +++ b/egraph.c @@ -666,7 +666,8 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) if (niter > 2000) niter = 2000; } - /* int igraph_layout_kamada_kawai(const igraph_t *g, igraph_matrix_t *res, + /* http://igraph.sourceforge.net/doc/html/ch18s01.html#igraph_layout_kamada_kawai + * int igraph_layout_kamada_kawai(const igraph_t *g, igraph_matrix_t *res, * igraph_integer_t niter, igraph_real_t sigma, * igraph_real_t initemp, igraph_real_t coolexp, * igraph_real_t kkconst, igraph_bool_t use_seed, @@ -674,7 +675,7 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) * const igraph_vector_t *maxx, * const igraph_vector_t *miny, * const igraph_vector_t *maxy); - * Defaults from igraph doc : + * Defaults : * igraph_layout_kamada_kawai(&eg->graph2, &eg->coords2, * 1000, eg->vertices_count / 4, 10, 0.99, * eg->vertices_count ^ 2, 1, @@ -695,14 +696,15 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) if (niter > 500) niter = 500; } - /* int igraph_layout_graphopt(const igraph_t *g, igraph_matrix_t *res, + /* http://igraph.sourceforge.net/doc/html/ch18s01.html#igraph_layout_graphopt + * int igraph_layout_graphopt(const igraph_t *g, igraph_matrix_t *res, * igraph_integer_t niter, * igraph_real_t node_charge, igraph_real_t node_mass, * igraph_real_t spring_length, * igraph_real_t spring_constant, * igraph_real_t max_sa_movement, * igraph_bool_t use_seed); - * Defaults from igraph doc : + * Defaults : * igraph_layout_graphopt(&eg->graph2, &eg->coords2, * 1000, 0.001, 10, 0, 1, 5, 1); */ -- cgit v1.2.3-59-g8ed1b From 7895d5d09f9af4db1f41dadd0bc04409c75417ba Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 00:37:20 +0100 Subject: oops fix toolbar buttons --- examples/demoapp.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/examples/demoapp.c b/examples/demoapp.c index 3e82b8a..d6fcf9b 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -3,7 +3,8 @@ #include #include -Evas_Object *_mainwin, *_egraph; +Evas_Object *_mainwin; +Evas_Object *_egraph; Eina_List *_vertice_list = NULL; static void @@ -13,6 +14,9 @@ _cb_add_edge(void *data, Evas_Object *obj, void *event_info) int ran, count; char buf[64]; + if (!_egraph) + return; + count = eina_list_count(_vertice_list); if (count == 0) { a = egraph_vertice_add(_egraph, "first", NULL); @@ -34,6 +38,9 @@ _cb_add_50edges(void *data, Evas_Object *obj, void *event_info) { int i; + if (!_egraph) + return; + for (i=0; i<50; i++) _cb_add_edge(data, obj, event_info); } @@ -43,6 +50,9 @@ _cb_add_500edges(void *data, Evas_Object *obj, void *event_info) { int i; + if (!_egraph) + return; + for (i=0; i<500; i++) _cb_add_edge(data, obj, event_info); } @@ -53,6 +63,9 @@ _cb_del_edges(void *data, Evas_Object *obj, void *event_info) Eina_List *l; Egraph_Vertice *v; + if (!_egraph) + return; + EINA_LIST_FOREACH(_vertice_list, l, v) egraph_vertice_del(_egraph, v); @@ -68,24 +81,36 @@ _cb_show_nodes(void *data, Evas_Object *obj, void *event_info) static void _cb_show_labels(void *data, Evas_Object *obj, void *event_info) { + if (!_egraph) + return; + egraph_display_names_set(_egraph, elm_check_state_get(obj)); } static void _cb_show_edges(void *data, Evas_Object *obj, void *event_info) { + if (!_egraph) + return; + egraph_display_edges_set(_egraph, elm_check_state_get(obj)); } static void _cb_use_animations(void *data, Evas_Object *obj, void *event_info) { + if (!_egraph) + return; + egraph_use_animations_set(_egraph, elm_check_state_get(obj)); } static void _cb_do_improvements(void *data, Evas_Object *obj, void *event_info) { + if (!_egraph) + return; + egraph_do_improvements_set(_egraph, elm_check_state_get(obj)); } @@ -96,6 +121,9 @@ cb_layout_changed(void *data, Evas_Object *obj, void *event_info) char *selected; int layout; + if (!_egraph) + return; + it = event_info; selected = elm_object_item_text_get(it); layout = EGRAPH_LAYOUT_DEFAULT; @@ -142,6 +170,7 @@ elm_main(int argc, char **argv) elm_toolbar_homogeneous_set(tb, EINA_FALSE); elm_toolbar_horizontal_set(tb, EINA_FALSE); elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_MENU); + elm_toolbar_select_mode_set(tb, ELM_OBJECT_SELECT_MODE_ALWAYS); elm_toolbar_transverse_expanded_set(tb, EINA_TRUE); elm_object_style_set(tb, "item_centered"); evas_object_size_hint_weight_set(tb, 0.0, EVAS_HINT_EXPAND); -- cgit v1.2.3-59-g8ed1b From bc8c8367d3edb17606ca862de2199f7112f94f46 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 00:38:19 +0100 Subject: tweak spring_length in igraph_layout_graphopt() to have more space between vertices by default --- egraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egraph.c b/egraph.c index ea2f5ba..29653b8 100644 --- a/egraph.c +++ b/egraph.c @@ -709,7 +709,7 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) * 1000, 0.001, 10, 0, 1, 5, 1); */ igraph_layout_graphopt(&eg->graph2, &eg->coords2, - niter, 0.003, 10, 0, 1, 5, 1); + niter, 0.003, 10, 10, 1, 5, 1); } if (DEBUG) printf("[-] _cb_layouting_run end\n"); -- cgit v1.2.3-59-g8ed1b From 4a377f12d83af4287457752249691aad16a22ab0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 00:48:28 +0100 Subject: fix defaults in comments for igraph_layout_graphopt() --- egraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egraph.c b/egraph.c index 29653b8..dc1304e 100644 --- a/egraph.c +++ b/egraph.c @@ -706,7 +706,7 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) * igraph_bool_t use_seed); * Defaults : * igraph_layout_graphopt(&eg->graph2, &eg->coords2, - * 1000, 0.001, 10, 0, 1, 5, 1); + * 1000, 0.001, 30, 0, 1, 5, 0); */ igraph_layout_graphopt(&eg->graph2, &eg->coords2, niter, 0.003, 10, 10, 1, 5, 1); -- cgit v1.2.3-59-g8ed1b From 98ce389129700c09ee3e42de4f2ca4a204addeda Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 00:59:54 +0100 Subject: fix function prototype declaration --- egraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egraph.c b/egraph.c index dc1304e..f685bc2 100644 --- a/egraph.c +++ b/egraph.c @@ -17,7 +17,7 @@ static void _smart_del(Evas_Object *obj); static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y); static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); static void _edge_v2_add(Egraph *eg, Egraph_Edge *e); -static void _edge_del(Egraph *eg, Egraph_Edge *e); +static void _edge_add(Egraph *eg, Egraph_Edge *e); static void _edge_v2_del(Egraph *eg, Egraph_Edge *e); static void _edge_del(Egraph *eg, Egraph_Edge *e); static void _vertice_v2_add(Egraph *eg, Egraph_Vertice *v); -- cgit v1.2.3-59-g8ed1b From 3355582331f1b911da618f56b0174a351c6a2643 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 01:19:47 +0100 Subject: add 50 edges on app startup --- examples/demoapp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/demoapp.c b/examples/demoapp.c index d6fcf9b..2ae0e75 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -275,6 +275,8 @@ elm_main(int argc, char **argv) _egraph = egraph; _mainwin = win; + _cb_add_50edges(NULL, NULL, NULL); + elm_run(); retval = 0; -- cgit v1.2.3-59-g8ed1b From cfea1f2fb70768ea7fef905036345eea6e8e590d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 01:32:28 +0100 Subject: reference Core library for the future --- doc/TODO.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/TODO.txt b/doc/TODO.txt index b50f2a4..3904656 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -51,3 +51,9 @@ see elementary/src/bin/test_gesture_layer3.c 04:48 <@raster> one of the elm demos does this 04:48 <@raster> for soming/rotating with little photos 04:48 <@raster> multitouch test stuff + +* speed: from Thanatermesis : +the Core library (https://github.com/acaudwell/Core) +used by : +http://code.google.com/p/logstalgia/ +https://github.com/acaudwell/Gource (http://code.google.com/p/gource/) -- cgit v1.2.3-59-g8ed1b From 82b729be887a54d570f2e876938852c3cef6afc1 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 01:32:53 +0100 Subject: more on Core --- doc/TODO.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/TODO.txt b/doc/TODO.txt index 3904656..47e08d7 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -54,6 +54,7 @@ see elementary/src/bin/test_gesture_layer3.c * speed: from Thanatermesis : the Core library (https://github.com/acaudwell/Core) +renders to OpenGL directly used by : http://code.google.com/p/logstalgia/ https://github.com/acaudwell/Gource (http://code.google.com/p/gource/) -- cgit v1.2.3-59-g8ed1b From 365ae274c37c2de2ec4af88bb030fbffc053ce1b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 12:58:30 +0100 Subject: integration of EGRAPH_LAYOUT_FRUCHTERMANREINGOLD, and fixes to other layouts. --- Egraph.h | 3 +++ egraph.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/Egraph.h b/Egraph.h index 1aaedac..fb27507 100644 --- a/Egraph.h +++ b/Egraph.h @@ -13,6 +13,7 @@ typedef struct Egraph_Vertice Egraph_Vertice; typedef enum { EGRAPH_LAYOUT_GRAPHOPT = 0, EGRAPH_LAYOUT_KAMADAKAWAI = 1, + EGRAPH_LAYOUT_FRUCHTERMANREINGOLD = 2, } Egraph_Layout; #define EGRAPH_LAYOUT_DEFAULT EGRAPH_LAYOUT_GRAPHOPT #define EGRAPH_LAYOUTING_IMPROVEMENTS 5 @@ -44,6 +45,8 @@ struct Egraph { igraph_matrix_t coords; igraph_t graph2; // XXX remove use of graph here, see _repos() int graph2_vcount; + igraph_vector_t graph2_wmin, graph2_wmax, graph2_hmin, graph2_hmax; + int graph_wmin, graph_wmax, graph_hmin, graph_hmax; igraph_matrix_t coords2; }; diff --git a/egraph.c b/egraph.c index f685bc2..45c535a 100644 --- a/egraph.c +++ b/egraph.c @@ -136,6 +136,10 @@ egraph_new(Evas *evas, int directed) goto err; igraph_matrix_init(&eg->coords, 0, 2); igraph_matrix_init(&eg->coords2, 0, 2); + eg->graph_wmin = 0; + eg->graph_wmax = 200; + eg->graph_hmin = 0; + eg->graph_hmax = 200; return obj; @@ -575,9 +579,9 @@ _v3_update(Egraph *eg) Egraph_Vertice *v; Egraph_Edge *e; void *data; + float ranx, rany; int changes_count = 0; int changes_diff = 0; - int ranx, rany; int i, id; if (DEBUG) @@ -609,8 +613,10 @@ _v3_update(Egraph *eg) for (i=0; igraph2_vcount - changes_diff) + i; igraph_matrix_add_rows(&eg->coords2, 1); - ranx = random() % 200; // XXX make this evas obj size ? - rany = random() % 200; // XXX make this evas obj size ? + ranx = eg->graph_wmin + fmod((float)random() / 1000, (float)((eg->graph_wmax + 1) - eg->graph_wmin)); + rany = eg->graph_hmin + fmod((float)random() / 1000, (float)((eg->graph_hmax + 1) - eg->graph_hmin)); + if (DEBUG) + printf("ranx %6.3f rany %6.3f\n", ranx, rany); igraph_matrix_set(&eg->coords2, id, 0, ranx); igraph_matrix_set(&eg->coords2, id, 1, rany); } @@ -622,6 +628,22 @@ _v3_update(Egraph *eg) } } + if (eg->layout == EGRAPH_LAYOUT_FRUCHTERMANREINGOLD) { + /* set minimum and maximum for each node */ + /* XXX do that in layouting thread ? */ + if (DEBUG) + printf("g wmin %d wmax %d hmin %d hmax %d\n", + eg->graph_wmin, eg->graph_wmax, eg->graph_hmin, eg->graph_hmax); + igraph_vector_init(&eg->graph2_wmin, eg->graph2_vcount); + igraph_vector_init(&eg->graph2_wmax, eg->graph2_vcount); + igraph_vector_init(&eg->graph2_hmin, eg->graph2_vcount); + igraph_vector_init(&eg->graph2_hmax, eg->graph2_vcount); + igraph_vector_fill(&eg->graph2_wmin, eg->graph_wmin); + igraph_vector_fill(&eg->graph2_wmax, eg->graph_wmax); + igraph_vector_fill(&eg->graph2_hmin, eg->graph_hmin); + igraph_vector_fill(&eg->graph2_hmax, eg->graph_hmax); + } + eg->layouting.changes_diff = changes_diff; } @@ -685,6 +707,8 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) niter, eg->graph2_vcount, 10, 0.99, eg->vertices_count ^ 2, 1, NULL, NULL, NULL, NULL); + break; + case EGRAPH_LAYOUT_GRAPHOPT: if (eg->layouting.improvement) { niter = 300; @@ -710,6 +734,35 @@ _cb_layouting_run(void *data, Ecore_Thread *thread) */ igraph_layout_graphopt(&eg->graph2, &eg->coords2, niter, 0.003, 10, 10, 1, 5, 1); + break; + + case EGRAPH_LAYOUT_FRUCHTERMANREINGOLD: + niter = 1000; + /* http://igraph.sourceforge.net/doc/html/ch18s01.html#igraph_layout_fruchterman_reingold + * int igraph_layout_fruchterman_reingold(const igraph_t *graph, igraph_matrix_t *res, + * igraph_integer_t niter, igraph_real_t maxdelta, + * igraph_real_t area, igraph_real_t coolexp, + * igraph_real_t repulserad, igraph_bool_t use_seed, + * const igraph_vector_t *weight, + * const igraph_vector_t *minx, + * const igraph_vector_t *maxx, + * const igraph_vector_t *miny, + * const igraph_vector_t *maxy); + * Defaults: + * igraph_layout_fruchterman_reingold(&eg->graph2, &eg->coords2, + * 500, eg->graph2_vcount, + * sqrt(eg->graph2_vcount) * sqrt(eg->graph2_vcount), 1.5, + * eg->graph2_vcount, 0, + * NULL, NULL, NULL, NULL, NULL); + */ + igraph_layout_fruchterman_reingold(&eg->graph2, &eg->coords2, + niter, 0.05, + sqrt(eg->graph2_vcount), 1.5, + sqrt(eg->graph2_vcount) * eg->graph2_vcount, 1, + NULL, NULL, NULL, NULL, NULL); + //&eg->graph2_wmin, &eg->graph2_wmax, + //&eg->graph2_hmin, &eg->graph2_hmax); + break; } if (DEBUG) printf("[-] _cb_layouting_run end\n"); @@ -830,11 +883,24 @@ _reposition(Egraph *eg, int no_animation) evas_object_geometry_get(eg->obj, &obj_x, &obj_y, &obj_w, &obj_h); _matrix_minmax_2v(&eg->coords, eg->graph_vcount, &gw_min, &gw_max, &gh_min, &gh_max); + eg->graph_wmin = gw_min; + eg->graph_wmax = gw_max; + eg->graph_hmin = gh_min; + eg->graph_hmax = gh_max; + if (DEBUG) printf("gw_min %6.3f gw_max %6.3f gh_min %6.3f gh_max %6.3f\n", gw_min, gw_max, gh_min, gh_max); - factor_w = (obj_w - VERTICE_W) / (gw_max - gw_min); - factor_h = (obj_h - VERTICE_H) / (gh_max - gh_min); + if (gw_max == gw_min) + factor_w = 1; + else + factor_w = (obj_w - VERTICE_W) / (gw_max - gw_min); + if (gh_max == gh_min) + factor_h = 1; + else + factor_h = (obj_h - VERTICE_H) / (gh_max - gh_min); + if (DEBUG) + printf("factor_w %6.3f factor_h %6.3f\n", factor_w, factor_h); for (vcur=0; vcurgraph_vcount; vcur++) { id = VAN(&eg->graph, "id", vcur); -- cgit v1.2.3-59-g8ed1b From 24370f1d8553140661ac4c6986bc4ec9d6079778 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 12:58:57 +0100 Subject: you can choose EGRAPH_LAYOUT_FRUCHTERMANREINGOLD now --- examples/demoapp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/demoapp.c b/examples/demoapp.c index 2ae0e75..7907251 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -131,6 +131,8 @@ cb_layout_changed(void *data, Evas_Object *obj, void *event_info) layout = EGRAPH_LAYOUT_KAMADAKAWAI; else if (!strcmp(selected, "GraphOpt")) layout = EGRAPH_LAYOUT_GRAPHOPT; + else if (!strcmp(selected, "Fruchterman R.")) + layout = EGRAPH_LAYOUT_FRUCHTERMANREINGOLD; egraph_layout_set(_egraph, layout); } @@ -199,6 +201,8 @@ elm_main(int argc, char **argv) elm_segment_control_item_selected_set(seg_it, EINA_TRUE); seg_it = elm_segment_control_item_add(sc, NULL, "Kamada K."); elm_segment_control_item_selected_set(seg_it, EINA_FALSE); + seg_it = elm_segment_control_item_add(sc, NULL, "Fruchterman R."); + elm_segment_control_item_selected_set(seg_it, EINA_FALSE); evas_object_smart_callback_add(sc, "changed", cb_layout_changed, NULL); evas_object_show(sc); tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); -- cgit v1.2.3-59-g8ed1b From 5bc129b7d13630757e4a210921c7a743023fd044 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 13:00:24 +0100 Subject: reference BUG about broken EGRAPH_LAYOUT_FRUCHTERMANREINGOLD --- doc/TODO.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/TODO.txt b/doc/TODO.txt index 47e08d7..af45746 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -13,6 +13,8 @@ it seems to be always the same node numbers that gets this wrong edge * BUG: vertices / vertices text fight for being on top. use evas layers ? add 500 edges to reproduce, and watch the nodes +* BUG: EGRAPH_LAYOUT_FRUCHTERMANREINGOLD is broken when adding many edges + * speed: evas_object_rectangles 04:40 <@raster> they add clipoouts 04:41 <@raster> make them just a bit translucent -- cgit v1.2.3-59-g8ed1b From 9c93f9725c9acba5981af0b714d2482a16817b99 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 15:49:39 +0100 Subject: it did bug again --- doc/bug_lockup_evas.txt | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index 2a57b6e..d91bcc6 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -35,4 +35,40 @@ run =============================================================================== +=============================================================================== +2012-12-10_15-48 + +ELM_ENGINE=opengl_x11 gdb ./examples/demoapp +run +// use the app, and it locks up during an animation +// Ctrl-C + +^C +Program received signal SIGINT, Interrupt. +0x00007ffff7233fd3 in rect_list_add_split_fuzzy (node=0x1ce6300, rects=0x9c49b8, accepted_error=) at lib/evas/common/evas_tiler.c:650 +650 current = ((rect_node_t *)cur_node)->rect; +(gdb) bt +#0 0x00007ffff7233fd3 in rect_list_add_split_fuzzy (node=0x1ce6300, rects=0x9c49b8, accepted_error=) at lib/evas/common/evas_tiler.c:650 +#1 rect_list_add_split_fuzzy_and_merge (node=0x1ce6300, rects=0x9c49b8, split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#2 _add_redraw (h=7, w=34, y=254, x=698, rects=0x9c49b8) at lib/evas/common/evas_tiler.c:956 +#3 evas_common_tilebuf_add_redraw (tb=0x9c4980, x=698, y=254, w=34, h=7) at lib/evas/common/evas_tiler.c:986 +#4 0x00007ffff71b2af2 in evas_object_render_pre_effect_updates (rects=0x68bed8, eo_obj=, is_v=1, was_v=) + at lib/evas/canvas/evas_object_main.c:343 +#5 0x00007ffff71f1bfc in _evas_render_phase1_direct (render_objects=0x139e3a0, active_objects=0x68bce0, e=, restack_objects=, + delete_objects=) at lib/evas/canvas/evas_render.c:231 +#6 evas_render_updates_internal (eo_e=0x68bc50, make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') at lib/evas/canvas/evas_render.c:1357 +#7 0x00007ffff71f3cd7 in _canvas_render_updates (eo_e=, _pd=, list=) at lib/evas/canvas/evas_render.c:1795 +#8 0x00007ffff6acba35 in _eo_op_internal (obj=0x68bc50, op_type=EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe158) at lib/eo/eo.c:363 +#9 0x00007ffff6acd6cd in _eo_dov_internal (p_list=0x7fffffffe158, op_type=EO_OP_TYPE_REGULAR, obj=0x68bc50) at lib/eo/eo.c:403 +#10 eo_do_internal (obj=0x68bc50, op_type=op_type@entry=EO_OP_TYPE_REGULAR) at lib/eo/eo.c:434 +#11 0x00007ffff71f3c5f in evas_render_updates (eo_e=) at lib/evas/canvas/evas_render.c:1779 +#12 0x00007fffe73d943a in _ecore_evas_x_render (ee=0x68a480) at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#13 0x00007ffff68ba7f1 in _ecore_evas_idle_enter (data=) at lib/ecore_evas/ecore_evas.c:59 +#14 0x00007ffff6f3c019 in _ecore_call_task_cb (data=, func=) at lib/ecore/ecore_private.h:300 +#15 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#16 0x00007ffff6f3e47b in _ecore_main_loop_iterate_internal (once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#17 0x00007ffff6f3eb27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 +#18 0x00000000004028de in elm_main (argc=1, argv=0x7fffffffe508) at demoapp.c:284 +#19 0x0000000000402923 in main (argc=1, argv=0x7fffffffe508) at demoapp.c:291 -- cgit v1.2.3-59-g8ed1b From d3ded5ce61dacc005014bbc15fe575f2084810ad Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 15:50:01 +0100 Subject: add edje --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index eae2587..dd1c889 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ # CFLAGS += -Werror -Wall -O2 -fPIC -shared -g CFLAGS += -Werror -Wall -fPIC -shared -g -CFLAGS += $(shell pkg-config --libs --cflags igraph) +CFLAGS += $(shell pkg-config --libs --cflags edje) CFLAGS += $(shell pkg-config --libs --cflags efx) +CFLAGS += $(shell pkg-config --libs --cflags igraph) PREFIX=/usr/local INCLUDEDIR=$(PREFIX)/include -- cgit v1.2.3-59-g8ed1b From edb31d85d0c6c6236811e90dfb8c8772ae39ac0b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Mon, 10 Dec 2012 23:53:34 +0100 Subject: again same evas bug. add more description and general context --- doc/bug_lockup_evas.txt | 56 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index d91bcc6..0225c3e 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -1,10 +1,20 @@ +This bug is a lockup of evas during rendering in my efl app. +App freeze and takes 100% CPU. Below are backtraces when gdb was running and +I interrupt it with Ctrl-C. + +At the time of crash, around 300objects total : +elementary interface + ~100 edje + ~100 evas_object_line + +This crash is not predictible from what I see, sometimes it goes fine for a long +time. + =============================================================================== 2012-12-09_18-10 ELM_ENGINE=opengl_x11 gdb ./examples/demoapp run -// use the app, and it locks up during an animation +// use the app, and it locks up during an animation (app takes 100% CPU) // Ctrl-C (gdb) bt @@ -41,7 +51,7 @@ run ELM_ENGINE=opengl_x11 gdb ./examples/demoapp run -// use the app, and it locks up during an animation +// use the app, and it locks up during an animation (app takes 100% CPU) // Ctrl-C ^C @@ -72,3 +82,45 @@ Program received signal SIGINT, Interrupt. #17 0x00007ffff6f3eb27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 #18 0x00000000004028de in elm_main (argc=1, argv=0x7fffffffe508) at demoapp.c:284 #19 0x0000000000402923 in main (argc=1, argv=0x7fffffffe508) at demoapp.c:291 + +=============================================================================== +2012-12-10_23-49 + +Lockup without opengl ! +I was using software rendering. + +gdb ./examples/demoapp +run + +// use the app, and it locks up during an animation (app takes 100% CPU) +// Ctrl-C + +^C +Program received signal SIGINT, Interrupt. +_calc_intra_outer_rect_area (outer=, intra=, a=..., b=...) at lib/evas/common/evas_tiler.c:524 +524 intra->area = intra->width * intra->height; +(gdb) bt +#0 _calc_intra_outer_rect_area (outer=, intra=, a=..., b=...) at lib/evas/common/evas_tiler.c:524 +#1 rect_list_add_split_fuzzy (node=0xb54050, rects=0x6927f8, accepted_error=) at lib/evas/common/evas_tiler.c:652 +#2 rect_list_add_split_fuzzy_and_merge (node=0xb54050, rects=0x6927f8, split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#3 _add_redraw (h=72, w=348, y=429, x=296, rects=0x6927f8) at lib/evas/common/evas_tiler.c:956 +#4 evas_common_tilebuf_add_redraw (tb=0x6927c0, x=296, y=429, w=348, h=72) at lib/evas/common/evas_tiler.c:986 +#5 0x00007ffff71b2af2 in evas_object_render_pre_effect_updates (rects=rects@entry=0x689ac8, eo_obj=eo_obj@entry=0x8d2360, is_v=is_v@entry=1, was_v=was_v@entry= + 1) at lib/evas/canvas/evas_object_main.c:343 +#6 0x00007ffff71ab60d in evas_object_image_render_pre (eo_obj=0x8d2360, obj=0x8d23f0) at lib/evas/canvas/evas_object_image.c:3768 +#7 0x00007ffff71f1668 in evas_render_updates_internal (eo_e=0x689840, make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') + at lib/evas/canvas/evas_render.c:1365 +#8 0x00007ffff71f3cd7 in _canvas_render_updates (eo_e=, _pd=, list=) at lib/evas/canvas/evas_render.c:1795 +#9 0x00007ffff6acba35 in _eo_op_internal (obj=0x689840, op_type=EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe168) at lib/eo/eo.c:363 +#10 0x00007ffff6acd6cd in _eo_dov_internal (p_list=0x7fffffffe168, op_type=EO_OP_TYPE_REGULAR, obj=0x689840) at lib/eo/eo.c:403 +#11 eo_do_internal (obj=0x689840, op_type=op_type@entry=EO_OP_TYPE_REGULAR) at lib/eo/eo.c:434 +#12 0x00007ffff71f3c5f in evas_render_updates (eo_e=) at lib/evas/canvas/evas_render.c:1779 +#13 0x00007fffe73d943a in _ecore_evas_x_render (ee=0x6880c0) at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#14 0x00007ffff68ba7f1 in _ecore_evas_idle_enter (data=) at lib/ecore_evas/ecore_evas.c:59 +#15 0x00007ffff6f3c019 in _ecore_call_task_cb (data=, func=) at lib/ecore/ecore_private.h:300 +#16 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#17 0x00007ffff6f3e47b in _ecore_main_loop_iterate_internal (once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#18 0x00007ffff6f3eb27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 +#19 0x00000000004028de in elm_main (argc=1, argv=0x7fffffffe518) at demoapp.c:284 +#20 0x0000000000402923 in main (argc=1, argv=0x7fffffffe518) at demoapp.c:291 -- cgit v1.2.3-59-g8ed1b From 50280a2b9c5e4f02903f5af81c5f40dc84da26c7 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 00:35:00 +0100 Subject: more info --- doc/bug_lockup_evas.txt | 75 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index 0225c3e..82b395e 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -7,6 +7,13 @@ elementary interface + ~100 edje + ~100 evas_object_line This crash is not predictible from what I see, sometimes it goes fine for a long time. +It seem to crash more when using more edje objects. + +svn info +Revision: 79909 + +uname -a +Linux balboa 3.6.7-1-ARCH #1 SMP PREEMPT Sun Nov 18 10:11:22 CET 2012 x86_64 GNU/Linux =============================================================================== 2012-12-09_18-10 @@ -124,3 +131,71 @@ _calc_intra_outer_rect_area (outer=, intra=) at lib/evas/common/evas_tiler.c:653 +653 area = current.area + r.area - intra.area; +(gdb) bt +#0 rect_list_add_split_fuzzy (node=0xfe0150, rects=0x6927f8, accepted_error=) at lib/evas/common/evas_tiler.c:653 +#1 rect_list_add_split_fuzzy_and_merge (node=0xfe0150, rects=0x6927f8, split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#2 _add_redraw (h=63, w=85, y=314, x=493, rects=0x6927f8) at lib/evas/common/evas_tiler.c:956 +#3 evas_common_tilebuf_add_redraw (tb=0x6927c0, x=493, y=314, w=85, h=63) at lib/evas/common/evas_tiler.c:986 +#4 0x00007ffff71b2b9d in evas_object_render_pre_effect_updates (rects=0x689ac8, eo_obj=, is_v=1, was_v=) + at lib/evas/canvas/evas_object_main.c:356 +#5 0x00007ffff71f1bfc in _evas_render_phase1_direct (render_objects=0x1b79f50, active_objects=0x6898d0, e=, restack_objects=, + delete_objects=) at lib/evas/canvas/evas_render.c:231 +#6 evas_render_updates_internal (eo_e=0x689840, make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') at lib/evas/canvas/evas_render.c:1357 +#7 0x00007ffff71f3cd7 in _canvas_render_updates (eo_e=, _pd=, list=) at lib/evas/canvas/evas_render.c:1795 +#8 0x00007ffff6acba35 in _eo_op_internal (obj=0x689840, op_type=EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe168) at lib/eo/eo.c:363 +#9 0x00007ffff6acd6cd in _eo_dov_internal (p_list=0x7fffffffe168, op_type=EO_OP_TYPE_REGULAR, obj=0x689840) at lib/eo/eo.c:403 +#10 eo_do_internal (obj=0x689840, op_type=op_type@entry=EO_OP_TYPE_REGULAR) at lib/eo/eo.c:434 +#11 0x00007ffff71f3c5f in evas_render_updates (eo_e=) at lib/evas/canvas/evas_render.c:1779 +#12 0x00007fffe73d943a in _ecore_evas_x_render (ee=0x6880c0) at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#13 0x00007ffff68ba7f1 in _ecore_evas_idle_enter (data=) at lib/ecore_evas/ecore_evas.c:59 +#14 0x00007ffff6f3c019 in _ecore_call_task_cb (data=, func=) at lib/ecore/ecore_private.h:300 +#15 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#16 0x00007ffff6f3e47b in _ecore_main_loop_iterate_internal (once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#17 0x00007ffff6f3eb27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 +#18 0x00000000004028de in elm_main (argc=1, argv=0x7fffffffe518) at demoapp.c:284 +#19 0x0000000000402923 in main (argc=1, argv=0x7fffffffe518) at demoapp.c:291 + +=============================================================================== +2012-12-11_00-34 + +// Same scenario + +^C +Program received signal SIGINT, Interrupt. +rect_list_add_split_fuzzy (node=0xb54370, rects=0x6927f8, accepted_error=) at lib/evas/common/evas_tiler.c:702 +702 else if (intra.area <= accepted_error) +(gdb) bt +#0 rect_list_add_split_fuzzy (node=0xb54370, rects=0x6927f8, accepted_error=) at lib/evas/common/evas_tiler.c:702 +#1 rect_list_add_split_fuzzy_and_merge (node=0xb54370, rects=0x6927f8, split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#2 _add_redraw (h=39, w=49, y=156, x=486, rects=0x6927f8) at lib/evas/common/evas_tiler.c:956 +#3 evas_common_tilebuf_add_redraw (tb=0x6927c0, x=486, y=156, w=49, h=39) at lib/evas/common/evas_tiler.c:986 +#4 0x00007ffff71b2af2 in evas_object_render_pre_effect_updates (rects=0x689ac8, eo_obj=, is_v=1, was_v=) + at lib/evas/canvas/evas_object_main.c:343 +#5 0x00007ffff71f1bfc in _evas_render_phase1_direct (render_objects=0x1671880, active_objects=0x6898d0, e=, restack_objects=, + delete_objects=) at lib/evas/canvas/evas_render.c:231 +#6 evas_render_updates_internal (eo_e=0x689840, make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') at lib/evas/canvas/evas_render.c:1357 +#7 0x00007ffff71f3cd7 in _canvas_render_updates (eo_e=, _pd=, list=) at lib/evas/canvas/evas_render.c:1795 +#8 0x00007ffff6acba35 in _eo_op_internal (obj=0x689840, op_type=EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe168) at lib/eo/eo.c:363 +#9 0x00007ffff6acd6cd in _eo_dov_internal (p_list=0x7fffffffe168, op_type=EO_OP_TYPE_REGULAR, obj=0x689840) at lib/eo/eo.c:403 +#10 eo_do_internal (obj=0x689840, op_type=op_type@entry=EO_OP_TYPE_REGULAR) at lib/eo/eo.c:434 +#11 0x00007ffff71f3c5f in evas_render_updates (eo_e=) at lib/evas/canvas/evas_render.c:1779 +#12 0x00007fffe73d943a in _ecore_evas_x_render (ee=0x6880c0) at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#13 0x00007ffff68ba7f1 in _ecore_evas_idle_enter (data=) at lib/ecore_evas/ecore_evas.c:59 +#14 0x00007ffff6f3c019 in _ecore_call_task_cb (data=, func=) at lib/ecore/ecore_private.h:300 +#15 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#16 0x00007ffff6f3e47b in _ecore_main_loop_iterate_internal (once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#17 0x00007ffff6f3eb27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 +#18 0x00000000004028de in elm_main (argc=1, argv=0x7fffffffe518) at demoapp.c:284 +#19 0x0000000000402923 in main (argc=1, argv=0x7fffffffe518) at demoapp.c:291 -- cgit v1.2.3-59-g8ed1b From 18ed626e95460ad197ce125885488a83284569a8 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 00:39:00 +0100 Subject: add support for theming of edges and vertices, and a default theme for vertices. add building in Makefile. add egraph_theme_file_set() to set a custom theme. --- Egraph.h | 8 ++++++ Makefile | 16 +++++++++--- egraph.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- egraph.edc | 32 ++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 16 deletions(-) create mode 100644 egraph.edc diff --git a/Egraph.h b/Egraph.h index fb27507..e8cb355 100644 --- a/Egraph.h +++ b/Egraph.h @@ -28,6 +28,7 @@ struct Egraph { int display_edges; int use_animations; int do_improvements; + char *theme_path; Egraph_Layout layout; struct { Ecore_Thread *thread; @@ -54,6 +55,7 @@ struct Egraph_Vertice { u_int32_t id; char *name; Evas_Object *o; + int o_usetheme; Evas_Object *o_text; Eina_List *edges; void *data; @@ -68,6 +70,7 @@ struct Egraph_Edge { Egraph_Vertice *a; Egraph_Vertice *b; Evas_Object *o; + int o_usetheme; void *data; u_int new : 1; u_int v2_new : 1; @@ -81,6 +84,11 @@ struct Egraph_Edge { */ Evas_Object *egraph_new(Evas *evas, int directed); +/** + * Configure egraph to use an edje theme + */ +void egraph_theme_file_set(Evas_Object *obj, char *path); + /** * Sets the layout of Egraph */ diff --git a/Makefile b/Makefile index dd1c889..3aa6042 100644 --- a/Makefile +++ b/Makefile @@ -6,25 +6,33 @@ CFLAGS += $(shell pkg-config --libs --cflags igraph) PREFIX=/usr/local INCLUDEDIR=$(PREFIX)/include +SHAREDIR=$(PREFIX)/share/egraph LIBDIR=$(PREFIX)/lib -LIBNAME=libegraph -TARGET = ${LIBNAME}.so SOURCES = egraph.c HEADERS = Egraph.h +EDC = egraph.edc +EDJ = $(EDC:.edc=.edj) OBJECTS = $(SOURCES:.c=.o) +LIBNAME = libegraph +TARGET = ${LIBNAME}.so -all: $(TARGET) +all: $(TARGET) $(EDJ) $(TARGET): $(OBJECTS) $(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS) +$(EDJ): + edje_cc $(EDC) $(EDJ) + install: @echo "installation of $(LIBNAME)" mkdir -p $(LIBDIR) mkdir -p $(INCLUDEDIR) + mkdir -p $(SHAREDIR) install -m 0644 $(TARGET) $(LIBDIR) install -m 0644 $(HEADERS) $(INCLUDEDIR) + install -m 0644 $(EDJ) $(SHAREDIR) clean: - rm -f $(TARGET) $(OBJECTS) + rm -f $(TARGET) $(OBJECTS) $(EDJ) diff --git a/egraph.c b/egraph.c index 45c535a..e09483b 100644 --- a/egraph.c +++ b/egraph.c @@ -1,5 +1,6 @@ #include #include +#include #include "Egraph.h" @@ -122,6 +123,7 @@ egraph_new(Evas *evas, int directed) eg->display_edges = 1; eg->use_animations = 1; eg->do_improvements = 1; + egraph_theme_file_set(obj, NULL); eg->layout = EGRAPH_LAYOUT_DEFAULT; /* needed for igraph attribute handling */ @@ -149,6 +151,25 @@ err: return NULL; } +void +egraph_theme_file_set(Evas_Object *obj, char *path) +{ + EGRAPH_DATA_GET(obj, eg); + + if (eg->theme_path) + free(eg->theme_path); + + if (!path) { + char buf[256]; + + snprintf(buf, sizeof(buf), + "%s/egraph.edj", + "/usr/local/share/egraph"); /* XXX use eina_prefix */ + path = buf; + } + eg->theme_path = strndup(path, 256); +} + void egraph_layout_set(Evas_Object *obj, Egraph_Layout layout) { @@ -279,6 +300,22 @@ _edge_v2_add(Egraph *eg, Egraph_Edge *e) igraph_add_edge(&eg->graph2, a_pos, b_pos); } +static Evas_Object * +_obj_new(Egraph *eg, char *group) +{ + Evas_Object *obj; + + obj = edje_object_add(eg->evas); + if (!obj || !edje_object_file_set(obj, eg->theme_path, group)) { + int err = edje_object_load_error_get(obj); + const char *errmsg = edje_load_error_str(err); + if (DEBUG) + fprintf(stderr, "Could not load the edje file - reason:%s\n", errmsg); + return NULL; + } + return obj; +} + static void _edge_add(Egraph *eg, Egraph_Edge *e) { @@ -292,9 +329,14 @@ _edge_add(Egraph *eg, Egraph_Edge *e) b_pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, e->b->id); igraph_add_edge(&eg->graph, a_pos, b_pos); - eobj = evas_object_line_add(eg->evas); + eobj = _obj_new(eg, "edge"); + if (eobj) + e->o_usetheme = 1; + else { + eobj = evas_object_line_add(eg->evas); + evas_object_color_set(eobj, 255, 0, 0, 255); + } evas_object_smart_member_add(eobj, eg->obj); - evas_object_color_set(eobj, 255, 0, 0, 255); e->o = eobj; e->a->edges = eina_list_append(e->a->edges, e); @@ -418,12 +460,16 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) SETVAN(&eg->graph, "id", eg->graph_vcount, v->id); eg->graph_vcount++; - vobj = evas_object_rectangle_add(eg->evas); + vobj = _obj_new(eg, "vertice"); + if (vobj) + v->o_usetheme = 1; + else { + vobj = evas_object_rectangle_add(eg->evas); + evas_object_color_set(vobj, 0, 0, 255, 255); + } evas_object_smart_member_add(vobj, eg->obj); - evas_object_color_set(vobj, 0, 0, 255, 255); evas_object_resize(vobj, VERTICE_OBJ_W, VERTICE_OBJ_H); evas_object_event_callback_add(vobj, EVAS_CALLBACK_MOVE, _cb_vertice_move, v); - v->o = vobj; text = evas_object_text_add(eg->evas); @@ -853,15 +899,27 @@ _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) evas_object_show(e->o); e->new = 0; } - evas_object_line_xy_get(e->o, &ax, &ay, &bx, &by); - if (e->a == v) { - ax = x + w/2; - ay = y + h/2; + if (e->o_usetheme) { + Evas_Map *m; + + m = evas_map_new(4); + //evas_map_alpha_set(m, 0); + evas_map_util_points_populate_from_object(m, e->o); + evas_map_util_rotate(m, 30, x + (w / 2), y + (h / 2)); + evas_object_map_set(e->o, m); + evas_object_map_enable_set(e->o, EINA_TRUE); // XXX do at init + evas_map_free(m); } else { - bx = x + w/2; - by = y + h/2; + evas_object_line_xy_get(e->o, &ax, &ay, &bx, &by); + if (e->a == v) { + ax = x + w/2; + ay = y + h/2; + } else { + bx = x + w/2; + by = y + h/2; + } + evas_object_line_xy_set(e->o, ax, ay, bx, by); } - evas_object_line_xy_set(e->o, ax, ay, bx, by); } } diff --git a/egraph.edc b/egraph.edc new file mode 100644 index 0000000..415b10e --- /dev/null +++ b/egraph.edc @@ -0,0 +1,32 @@ +collections { + group { + name: "vertice"; + max: 700 700; + min: 700 700; + images { + image: "data/vertice.png" COMP; + } + parts { + part { + name: "image"; + type: IMAGE; + description { + state: "default" 0.0; + max: 15 15; + min: 15 15; + image{ + normal: "data/vertice.png"; + } + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + } + description { + state: "down-state" 1.0; + inherit: "default" 0.0; + rel1.relative: 0.0 1.0; + rel2.relative: 0.0 0.0; + } + } + } + } +} -- cgit v1.2.3-59-g8ed1b From 5eb7e3e0befcbd20f7e30d581d5a9889eb127ef5 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 00:53:47 +0100 Subject: oops forgot to add image for theme --- data/vertice.png | Bin 0 -> 4505 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 data/vertice.png diff --git a/data/vertice.png b/data/vertice.png new file mode 100644 index 0000000..7cf4dcd Binary files /dev/null and b/data/vertice.png differ -- cgit v1.2.3-59-g8ed1b From 832a96f3d36b21d7fb49d5f9dc36e60367df9d55 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 05:35:13 +0100 Subject: add edges theme support, and add it to the default theme. added a rectangle to to help stacking edges below vertices, but it still has stacking problems. --- Egraph.h | 1 + data/edge.png | Bin 0 -> 372 bytes data/edge.xcf | Bin 0 -> 8278 bytes egraph.c | 50 +++++++++++++++++++++++++++++++++++++++++--------- egraph.edc | 30 ++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 9 deletions(-) create mode 100644 data/edge.png create mode 100644 data/edge.xcf diff --git a/Egraph.h b/Egraph.h index e8cb355..8d84e0a 100644 --- a/Egraph.h +++ b/Egraph.h @@ -21,6 +21,7 @@ typedef enum { struct Egraph { Evas_Object_Smart_Clipped_Data __clipped_data; Evas_Object *obj; + Evas_Object *split_vertice_edge; Evas *evas; int graph_directed; int display_vertices; diff --git a/data/edge.png b/data/edge.png new file mode 100644 index 0000000..f6bbfc4 Binary files /dev/null and b/data/edge.png differ diff --git a/data/edge.xcf b/data/edge.xcf new file mode 100644 index 0000000..9481336 Binary files /dev/null and b/data/edge.xcf differ diff --git a/egraph.c b/egraph.c index e09483b..4e3e8ed 100644 --- a/egraph.c +++ b/egraph.c @@ -104,6 +104,7 @@ Evas_Object * egraph_new(Evas *evas, int directed) { Evas_Object *obj = NULL; + Evas_Object *rect; Egraph *eg; int i; @@ -116,6 +117,11 @@ egraph_new(Evas *evas, int directed) eg = evas_object_smart_data_get(obj); if (!eg) goto err; eg->obj = obj; + rect = evas_object_rectangle_add(eg->evas); + evas_object_color_set(rect, 0, 0, 0, 0); + evas_object_show(rect); // XXX + evas_object_smart_member_add(rect, obj); + eg->split_vertice_edge = rect; eg->graph_directed = directed; eg->display_vertices = 1; @@ -330,13 +336,15 @@ _edge_add(Egraph *eg, Egraph_Edge *e) igraph_add_edge(&eg->graph, a_pos, b_pos); eobj = _obj_new(eg, "edge"); - if (eobj) + if (eobj) { e->o_usetheme = 1; - else { + evas_object_resize(eobj, VERTICE_OBJ_W, VERTICE_OBJ_H); // XXX rm + } else { eobj = evas_object_line_add(eg->evas); evas_object_color_set(eobj, 255, 0, 0, 255); } evas_object_smart_member_add(eobj, eg->obj); + evas_object_stack_below(eobj, eg->split_vertice_edge); e->o = eobj; e->a->edges = eina_list_append(e->a->edges, e); @@ -468,6 +476,7 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) evas_object_color_set(vobj, 0, 0, 255, 255); } evas_object_smart_member_add(vobj, eg->obj); + evas_object_stack_above(vobj, eg->split_vertice_edge); evas_object_resize(vobj, VERTICE_OBJ_W, VERTICE_OBJ_H); evas_object_event_callback_add(vobj, EVAS_CALLBACK_MOVE, _cb_vertice_move, v); v->o = vobj; @@ -878,9 +887,12 @@ _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) EGRAPH_DATA_GET(evas_object_smart_parent_get(obj), eg); Egraph_Vertice *v; Egraph_Edge *e; + Evas_Map *m; Eina_List *l; int x, y, w, h; - int ax, ay, bx, by; + int ax, ay, bx, by, aw, ah, bw, bh; + int p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y; + float a; v = data; evas_object_geometry_get(v->o, &x, &y, &w, &h); @@ -890,7 +902,6 @@ _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) evas_object_move(v->o_text, x+3, y+8); else evas_object_move(v->o_text, x, y); - evas_object_raise(v->o_text); } EINA_LIST_FOREACH(v->edges, l, e) { @@ -900,12 +911,34 @@ _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) e->new = 0; } if (e->o_usetheme) { - Evas_Map *m; - + /* XXX we map the edges once per node = 2 times ... */ + evas_object_move(e->o, x, y); m = evas_map_new(4); - //evas_map_alpha_set(m, 0); + evas_map_smooth_set(m, 1); + // XXX do i need ? evas_map_alpha_set(m, 0); evas_map_util_points_populate_from_object(m, e->o); - evas_map_util_rotate(m, 30, x + (w / 2), y + (h / 2)); + //evas_map_util_points_populate_from_geometry(m, x, y, 10, 50, 0); + evas_object_geometry_get(e->a->o, &ax, &ay, &aw, &ah); + evas_object_geometry_get(e->b->o, &bx, &by, &bw, &bh); + ax = ax + aw / 2; ay = ay + ah / 2; + bx = bx + bw / 2; by = by + bh / 2; + aw = aw / 2; ah = ah / 2; + bw = bw / 2; bh = bh / 2; + /* rotate edge endpoints */ + a = atan2(by - ay, bx - ax); +#define ROTX(x, h, a) (-sin(a)*h + x) +#define ROTY(y, h, a) (cos(a)*h + y) + p0x = ROTX(ax, ah, a); p0y = ROTY(ay, ah, a); + p1x = ROTX(ax, -ah, a); p1y = ROTY(ay, -ah, a); + p2x = ROTX(bx, bh, a); p2y = ROTY(by, bh, a); + p3x = ROTX(bx, -bh, a); p3y = ROTY(by, -bh, a); + printf("(%d,%d) (%d,%d) (%d,%d) (%d,%d)\n", + p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y); + /* set edge endpoints */ + evas_map_point_coord_set(m, 0, p2x, p2y, 0); + evas_map_point_coord_set(m, 1, p0x, p0y, 0); + evas_map_point_coord_set(m, 2, p1x, p1y, 0); + evas_map_point_coord_set(m, 3, p3x, p3y, 0); evas_object_map_set(e->o, m); evas_object_map_enable_set(e->o, EINA_TRUE); // XXX do at init evas_map_free(m); @@ -978,7 +1011,6 @@ _reposition(Egraph *eg, int no_animation) &(Evas_Point){ x, y }, 1.0, NULL, NULL); else evas_object_move(v->o, x, y); - evas_object_raise(v->o); if (eg->display_names) { evas_object_raise(v->o_text); } diff --git a/egraph.edc b/egraph.edc index 415b10e..f411674 100644 --- a/egraph.edc +++ b/egraph.edc @@ -29,4 +29,34 @@ collections { } } } + group { + name: "edge"; + max: 700 700; + min: 700 700; + images { + image: "data/edge.png" COMP; + } + parts { + part { + name: "image"; + type: IMAGE; + description { + state: "default" 0.0; + max: 50 10; + min: 50 10; + image{ + normal: "data/edge.png"; + } + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + } + description { + state: "down-state" 1.0; + inherit: "default" 0.0; + rel1.relative: 0.0 1.0; + rel2.relative: 0.0 0.0; + } + } + } + } } -- cgit v1.2.3-59-g8ed1b From 3a73aac8b840fb4651ca4f37ef47c3c53fe6fdc0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 05:39:22 +0100 Subject: again evas lockup --- doc/bug_lockup_evas.txt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index 82b395e..62cab26 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -199,3 +199,38 @@ rect_list_add_split_fuzzy (node=0xb54370, rects=0x6927f8, accepted_error=) at lib/evas/common/evas_tiler.c:650 +650 current = ((rect_node_t *)cur_node)->rect; +(gdb) bt +#0 rect_list_add_split_fuzzy (node=0xcf4c20, rects=0x692788, accepted_error=) at lib/evas/common/evas_tiler.c:650 +#1 rect_list_add_split_fuzzy_and_merge (node=0xcf4c20, rects=0x692788, split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#2 _add_redraw (h=16, w=1047, y=240, x=263, rects=0x692788) at lib/evas/common/evas_tiler.c:956 +#3 evas_common_tilebuf_add_redraw (tb=0x692750, x=263, y=240, w=1047, h=16) at lib/evas/common/evas_tiler.c:986 +#4 0x00007ffff71b2af2 in evas_object_render_pre_effect_updates (rects=rects@entry=0x689a58, eo_obj=eo_obj@entry=0x1100690, is_v=is_v@entry=1, + was_v=was_v@entry=1) at lib/evas/canvas/evas_object_main.c:343 +#5 0x00007ffff71ab60d in evas_object_image_render_pre (eo_obj=0x1100690, obj=0x1100720) at lib/evas/canvas/evas_object_image.c:3768 +#6 0x00007ffff71f1bfc in _evas_render_phase1_direct (render_objects=0x1100690, active_objects=0x689860, e=, restack_objects=, + delete_objects=) at lib/evas/canvas/evas_render.c:231 +#7 evas_render_updates_internal (eo_e=0x6897d0, make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') at lib/evas/canvas/evas_render.c:1357 +#8 0x00007ffff71f3cd7 in _canvas_render_updates (eo_e=, _pd=, list=) at lib/evas/canvas/evas_render.c:1795 +#9 0x00007ffff6acba35 in _eo_op_internal (obj=0x6897d0, op_type=EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe1d8) at lib/eo/eo.c:363 +#10 0x00007ffff6acd6cd in _eo_dov_internal (p_list=0x7fffffffe1d8, op_type=EO_OP_TYPE_REGULAR, obj=0x6897d0) at lib/eo/eo.c:403 +#11 eo_do_internal (obj=0x6897d0, op_type=op_type@entry=EO_OP_TYPE_REGULAR) at lib/eo/eo.c:434 +#12 0x00007ffff71f3c5f in evas_render_updates (eo_e=) at lib/evas/canvas/evas_render.c:1779 +#13 0x00007fffe73d743a in _ecore_evas_x_render (ee=0x688050) at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#14 0x00007ffff68ba7f1 in _ecore_evas_idle_enter (data=) at lib/ecore_evas/ecore_evas.c:59 +#15 0x00007ffff6f3c019 in _ecore_call_task_cb (data=, func=) at lib/ecore/ecore_private.h:300 +#16 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#17 0x00007ffff6f3e47b in _ecore_main_loop_iterate_internal (once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#18 0x00007ffff6f3eb27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 +#19 0x00000000004028ce in elm_main (argc=1, argv=0x7fffffffe588) at demoapp.c:284 +#20 0x0000000000402913 in main (argc=1, argv=0x7fffffffe588) at demoapp.c:291 -- cgit v1.2.3-59-g8ed1b From 319b2084748a1613dd5d2947702870e8500469a7 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 05:41:03 +0100 Subject: remove debug printf --- egraph.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/egraph.c b/egraph.c index 4e3e8ed..b3990b9 100644 --- a/egraph.c +++ b/egraph.c @@ -932,8 +932,6 @@ _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) p1x = ROTX(ax, -ah, a); p1y = ROTY(ay, -ah, a); p2x = ROTX(bx, bh, a); p2y = ROTY(by, bh, a); p3x = ROTX(bx, -bh, a); p3y = ROTY(by, -bh, a); - printf("(%d,%d) (%d,%d) (%d,%d) (%d,%d)\n", - p0x, p0y, p1x, p1y, p2x, p2y, p3x, p3y); /* set edge endpoints */ evas_map_point_coord_set(m, 0, p2x, p2y, 0); evas_map_point_coord_set(m, 1, p0x, p0y, 0); -- cgit v1.2.3-59-g8ed1b From 23edd2b5d1917b21656b798e8cdd866047f00416 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 05:44:30 +0100 Subject: again, != bt --- doc/bug_lockup_evas.txt | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index 62cab26..e75bf7f 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -234,3 +234,55 @@ rect_list_add_split_fuzzy (node=0xcf4c20, rects=0x692788, accepted_error=, intra=, a=..., b=...) at lib/evas/common/evas_tiler.c:498 +498 if (a.top < b.top) +(gdb) bt +#0 _calc_intra_outer_rect_area (outer=, intra=, a=..., b=...) at lib/evas/common/evas_tiler.c:498 +#1 rect_list_add_split_fuzzy (node=0x1acbb00, rects=0x93f238, accepted_error=) at lib/evas/common/evas_tiler.c:652 +#2 rect_list_add_split_fuzzy_and_merge (node=0x1acbb00, rects=0x93f238, split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#3 _add_redraw (h=52, w=371, y=437, x=826, rects=0x93f238) at lib/evas/common/evas_tiler.c:956 +#4 evas_common_tilebuf_add_redraw (tb=0x93f200, x=826, y=437, w=371, h=52) at lib/evas/common/evas_tiler.c:986 +#5 0x00007ffff71ed67f in _evas_render_prev_cur_clip_cache_add (obj=obj@entry=0x1c752b0, e=0x68bc90, e=0x68bc90) at lib/evas/canvas/evas_render.c:158 +#6 0x00007ffff71ee940 in _evas_render_phase1_object_process (e=e@entry=0x68bc90, eo_obj=0x1c75220, active_objects=active_objects@entry=0x68bda8, + restack_objects=restack_objects@entry=0x68bdc8, delete_objects=delete_objects@entry=0x68bd88, render_objects=render_objects@entry=0x68bde8, restack=0, + redraw_all=redraw_all@entry=0x7fffffffe0ec, mapped_parent=mapped_parent@entry=0 '\000') at lib/evas/canvas/evas_render.c:355 +#7 0x00007ffff71eeaf6 in _evas_render_phase1_object_process (e=e@entry=0x68bc90, eo_obj=, active_objects=active_objects@entry=0x68bda8, + restack_objects=restack_objects@entry=0x68bdc8, delete_objects=delete_objects@entry=0x68bd88, render_objects=render_objects@entry=0x68bde8, restack=0, + redraw_all=redraw_all@entry=0x7fffffffe0ec, mapped_parent=mapped_parent@entry=0 '\000') at lib/evas/canvas/evas_render.c:413 +#8 0x00007ffff71eeaf6 in _evas_render_phase1_object_process (e=e@entry=0x68bc90, eo_obj=, active_objects=active_objects@entry=0x68bda8, + restack_objects=restack_objects@entry=0x68bdc8, delete_objects=delete_objects@entry=0x68bd88, render_objects=render_objects@entry=0x68bde8, restack=0, + redraw_all=redraw_all@entry=0x7fffffffe0ec, mapped_parent=mapped_parent@entry=0 '\000') at lib/evas/canvas/evas_render.c:413 +#9 0x00007ffff71eeaf6 in _evas_render_phase1_object_process (e=e@entry=0x68bc90, eo_obj=, active_objects=active_objects@entry=0x68bda8, + restack_objects=restack_objects@entry=0x68bdc8, delete_objects=delete_objects@entry=0x68bd88, render_objects=render_objects@entry=0x68bde8, restack=0, + redraw_all=redraw_all@entry=0x7fffffffe0ec, mapped_parent=mapped_parent@entry=0 '\000') at lib/evas/canvas/evas_render.c:413 +#10 0x00007ffff71eeaf6 in _evas_render_phase1_object_process (e=e@entry=0x68bc90, eo_obj=, active_objects=active_objects@entry=0x68bda8, + restack_objects=restack_objects@entry=0x68bdc8, delete_objects=delete_objects@entry=0x68bd88, render_objects=render_objects@entry=0x68bde8, restack=0, + redraw_all=redraw_all@entry=0x7fffffffe0ec, mapped_parent=mapped_parent@entry=0 '\000') at lib/evas/canvas/evas_render.c:413 +#11 0x00007ffff71eeaf6 in _evas_render_phase1_object_process (e=e@entry=0x68bc90, eo_obj=, active_objects=active_objects@entry=0x68bda8, + restack_objects=restack_objects@entry=0x68bdc8, delete_objects=delete_objects@entry=0x68bd88, render_objects=render_objects@entry=0x68bde8, + restack=restack@entry=0, redraw_all=redraw_all@entry=0x7fffffffe0ec, mapped_parent=mapped_parent@entry=0 '\000') at lib/evas/canvas/evas_render.c:413 +#12 0x00007ffff71f0f29 in _evas_render_phase1_process (redraw_all=0x7fffffffe0dc, render_objects=0x68bde8, delete_objects=0x68bd88, restack_objects=0x68bdc8, + active_objects=0x68bda8, e=0x68bc90) at lib/evas/canvas/evas_render.c:557 +#13 evas_render_updates_internal (eo_e=0x68bc00, make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') at lib/evas/canvas/evas_render.c:1337 +#14 0x00007ffff71f3cd7 in _canvas_render_updates (eo_e=, _pd=, list=) at lib/evas/canvas/evas_render.c:1795 +#15 0x00007ffff6acba35 in _eo_op_internal (obj=0x68bc00, op_type=EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe1b8) at lib/eo/eo.c:363 +#16 0x00007ffff6acd6cd in _eo_dov_internal (p_list=0x7fffffffe1b8, op_type=EO_OP_TYPE_REGULAR, obj=0x68bc00) at lib/eo/eo.c:403 +#17 eo_do_internal (obj=0x68bc00, op_type=op_type@entry=EO_OP_TYPE_REGULAR) at lib/eo/eo.c:434 +#18 0x00007ffff71f3c5f in evas_render_updates (eo_e=) at lib/evas/canvas/evas_render.c:1779 +#19 0x00007fffe73d743a in _ecore_evas_x_render (ee=0x68a430) at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#20 0x00007ffff68ba7f1 in _ecore_evas_idle_enter (data=) at lib/ecore_evas/ecore_evas.c:59 +#21 0x00007ffff6f3c019 in _ecore_call_task_cb (data=, func=) at lib/ecore/ecore_private.h:300 +#22 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#23 0x00007ffff6f3e47b in _ecore_main_loop_iterate_internal (once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#24 0x00007ffff6f3eb27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 +#25 0x00000000004028ce in elm_main (argc=1, argv=0x7fffffffe568) at demoapp.c:284 +#26 0x0000000000402913 in main (argc=1, argv=0x7fffffffe568) at demoapp.c:291 -- cgit v1.2.3-59-g8ed1b From 6f364993cfe6fa4b89c67fa82c0746e1280518de Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 05:47:23 +0100 Subject: insert new vertices faster when using animations --- egraph.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egraph.c b/egraph.c index b3990b9..90e3182 100644 --- a/egraph.c +++ b/egraph.c @@ -1006,7 +1006,7 @@ _reposition(Egraph *eg, int no_animation) v = eina_hash_find(eg->vertices, &id); if (eg->use_animations && !no_animation) efx_move(v->o, EFX_EFFECT_SPEED_DECELERATE, - &(Evas_Point){ x, y }, 1.0, NULL, NULL); + &(Evas_Point){ x, y }, 0.5, NULL, NULL); else evas_object_move(v->o, x, y); if (eg->display_names) { -- cgit v1.2.3-59-g8ed1b From 9dce76348983113855adf30129045736820fb429 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 05:59:33 +0100 Subject: add ways to enable/disable theming for edges and vertices separately, and add controls to do this in demoapp --- Egraph.h | 14 +++++++++++++- egraph.c | 46 +++++++++++++++++++++++++++++++++++----------- examples/demoapp.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 12 deletions(-) diff --git a/Egraph.h b/Egraph.h index 8d84e0a..f9474b2 100644 --- a/Egraph.h +++ b/Egraph.h @@ -29,7 +29,9 @@ struct Egraph { int display_edges; int use_animations; int do_improvements; - char *theme_path; + char *theme_path; + int theme_vertices; + int theme_edges; Egraph_Layout layout; struct { Ecore_Thread *thread; @@ -90,6 +92,16 @@ Evas_Object *egraph_new(Evas *evas, int directed); */ void egraph_theme_file_set(Evas_Object *obj, char *path); +/** + * Sets if egraph should theme the vertices + */ +void egraph_theme_vertices_set(Evas_Object *obj, int set); + +/** + * Sets if egraph should theme the edges + */ +void egraph_theme_edges_set(Evas_Object *obj, int set); + /** * Sets the layout of Egraph */ diff --git a/egraph.c b/egraph.c index 90e3182..b820fd4 100644 --- a/egraph.c +++ b/egraph.c @@ -130,6 +130,8 @@ egraph_new(Evas *evas, int directed) eg->use_animations = 1; eg->do_improvements = 1; egraph_theme_file_set(obj, NULL); + eg->theme_vertices = 1; + eg->theme_edges = 1; eg->layout = EGRAPH_LAYOUT_DEFAULT; /* needed for igraph attribute handling */ @@ -176,6 +178,22 @@ egraph_theme_file_set(Evas_Object *obj, char *path) eg->theme_path = strndup(path, 256); } +void +egraph_theme_vertices_set(Evas_Object *obj, int set) +{ + EGRAPH_DATA_GET(obj, eg); + + eg->theme_vertices = set; +} + +void +egraph_theme_edges_set(Evas_Object *obj, int set) +{ + EGRAPH_DATA_GET(obj, eg); + + eg->theme_edges = set; +} + void egraph_layout_set(Evas_Object *obj, Egraph_Layout layout) { @@ -325,7 +343,7 @@ _obj_new(Egraph *eg, char *group) static void _edge_add(Egraph *eg, Egraph_Edge *e) { - Evas_Object *eobj; + Evas_Object *eobj = NULL; int a_pos, b_pos; e->new = 1; @@ -335,11 +353,14 @@ _edge_add(Egraph *eg, Egraph_Edge *e) b_pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, e->b->id); igraph_add_edge(&eg->graph, a_pos, b_pos); - eobj = _obj_new(eg, "edge"); - if (eobj) { - e->o_usetheme = 1; - evas_object_resize(eobj, VERTICE_OBJ_W, VERTICE_OBJ_H); // XXX rm - } else { + if (eg->theme_edges) { + eobj = _obj_new(eg, "edge"); + if (eobj) { + e->o_usetheme = 1; + evas_object_resize(eobj, VERTICE_OBJ_W, VERTICE_OBJ_H); // XXX rm + } + } + if (!eobj) { eobj = evas_object_line_add(eg->evas); evas_object_color_set(eobj, 255, 0, 0, 255); } @@ -459,7 +480,8 @@ _vertice_v2_add(Egraph *eg, Egraph_Vertice *v) static void _vertice_add(Egraph *eg, Egraph_Vertice *v) { - Evas_Object *vobj, *text; + Evas_Object *vobj = NULL; + Evas_Object *text; v->new = 1; v->v2_new = 0; @@ -468,10 +490,12 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) SETVAN(&eg->graph, "id", eg->graph_vcount, v->id); eg->graph_vcount++; - vobj = _obj_new(eg, "vertice"); - if (vobj) - v->o_usetheme = 1; - else { + if (eg->theme_vertices) { + vobj = _obj_new(eg, "vertice"); + if (vobj) + v->o_usetheme = 1; + } + if (!vobj) { vobj = evas_object_rectangle_add(eg->evas); evas_object_color_set(vobj, 0, 0, 255, 255); } diff --git a/examples/demoapp.c b/examples/demoapp.c index 7907251..6f012a3 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -114,6 +114,24 @@ _cb_do_improvements(void *data, Evas_Object *obj, void *event_info) egraph_do_improvements_set(_egraph, elm_check_state_get(obj)); } +static void +_cb_use_theme_v(void *data, Evas_Object *obj, void *event_info) +{ + if (!_egraph) + return; + + egraph_theme_vertices_set(_egraph, elm_check_state_get(obj)); +} + +static void +_cb_use_theme_e(void *data, Evas_Object *obj, void *event_info) +{ + if (!_egraph) + return; + + egraph_theme_edges_set(_egraph, elm_check_state_get(obj)); +} + static void cb_layout_changed(void *data, Evas_Object *obj, void *event_info) { @@ -243,6 +261,20 @@ elm_main(int argc, char **argv) evas_object_smart_callback_add(ck, "changed", _cb_do_improvements, NULL); tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", ck); + ck = elm_check_add(win); + elm_object_text_set(ck, "Use theme for vertices"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_use_theme_v, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); + ck = elm_check_add(win); + elm_object_text_set(ck, "Use theme for edges"); + elm_check_state_set(ck, EINA_TRUE); + evas_object_show(ck); + evas_object_smart_callback_add(ck, "changed", _cb_use_theme_e, NULL); + tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); + elm_object_item_part_content_set(tb_it, "object", ck); //elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); elm_toolbar_item_append(tb, "exit", "Quit", _cb_on_done, NULL); -- cgit v1.2.3-59-g8ed1b From 176bf0936b2315de30b0a44c0c8ec3abff2a710a Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 06:07:43 +0100 Subject: tweak vertices size --- egraph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index b820fd4..31f92e3 100644 --- a/egraph.c +++ b/egraph.c @@ -6,8 +6,8 @@ #define DEBUG 0 -#define VERTICE_OBJ_W 10 -#define VERTICE_OBJ_H 10 +#define VERTICE_OBJ_W 15 +#define VERTICE_OBJ_H 15 #define VERTICE_TEXT_W 20 // XXX dynamicaly get the max on each new name #define VERTICE_TEXT_H 10 #define VERTICE_W (VERTICE_OBJ_W + VERTICE_TEXT_W) -- cgit v1.2.3-59-g8ed1b From 393ce41c3ab3daf6584539dc510a8ca902af78d0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 06:08:33 +0100 Subject: remove old comments --- egraph.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/egraph.c b/egraph.c index 31f92e3..fe9ac39 100644 --- a/egraph.c +++ b/egraph.c @@ -939,9 +939,7 @@ _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) evas_object_move(e->o, x, y); m = evas_map_new(4); evas_map_smooth_set(m, 1); - // XXX do i need ? evas_map_alpha_set(m, 0); evas_map_util_points_populate_from_object(m, e->o); - //evas_map_util_points_populate_from_geometry(m, x, y, 10, 50, 0); evas_object_geometry_get(e->a->o, &ax, &ay, &aw, &ah); evas_object_geometry_get(e->b->o, &bx, &by, &bw, &bh); ax = ax + aw / 2; ay = ay + ah / 2; -- cgit v1.2.3-59-g8ed1b From 0504f25f5748467727f569ebfe69a729b0f5efdd Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 06:10:41 +0100 Subject: move function around, no functionnal change --- egraph.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/egraph.c b/egraph.c index fe9ac39..cb4d8e6 100644 --- a/egraph.c +++ b/egraph.c @@ -40,6 +40,7 @@ static void _reposition(Egraph *eg, int no_animation); static void _matrix_minmax_2v(const igraph_matrix_t *m, int row_count, float *c1min, float *c1max, float *c2min, float *c2max); +static Evas_Object *_edje_obj_new(Egraph *eg, char *group); static const Evas_Smart_Cb_Description _smart_callbacks[] = {{NULL, NULL}}; #define EGRAPH_DATA_GET(o, ptr) \ @@ -324,22 +325,6 @@ _edge_v2_add(Egraph *eg, Egraph_Edge *e) igraph_add_edge(&eg->graph2, a_pos, b_pos); } -static Evas_Object * -_obj_new(Egraph *eg, char *group) -{ - Evas_Object *obj; - - obj = edje_object_add(eg->evas); - if (!obj || !edje_object_file_set(obj, eg->theme_path, group)) { - int err = edje_object_load_error_get(obj); - const char *errmsg = edje_load_error_str(err); - if (DEBUG) - fprintf(stderr, "Could not load the edje file - reason:%s\n", errmsg); - return NULL; - } - return obj; -} - static void _edge_add(Egraph *eg, Egraph_Edge *e) { @@ -354,7 +339,7 @@ _edge_add(Egraph *eg, Egraph_Edge *e) igraph_add_edge(&eg->graph, a_pos, b_pos); if (eg->theme_edges) { - eobj = _obj_new(eg, "edge"); + eobj = _edje_obj_new(eg, "edge"); if (eobj) { e->o_usetheme = 1; evas_object_resize(eobj, VERTICE_OBJ_W, VERTICE_OBJ_H); // XXX rm @@ -491,7 +476,7 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) eg->graph_vcount++; if (eg->theme_vertices) { - vobj = _obj_new(eg, "vertice"); + vobj = _edje_obj_new(eg, "vertice"); if (vobj) v->o_usetheme = 1; } @@ -1068,3 +1053,20 @@ _matrix_minmax_2v(const igraph_matrix_t *m, int row_count, else if (val > *c2max) *c2max = val; } } + +static Evas_Object * +_edje_obj_new(Egraph *eg, char *group) +{ + Evas_Object *obj; + + obj = edje_object_add(eg->evas); + if (!obj || !edje_object_file_set(obj, eg->theme_path, group)) { + int err = edje_object_load_error_get(obj); + const char *errmsg = edje_load_error_str(err); + if (DEBUG) + fprintf(stderr, "Could not load the edje file - reason:%s\n", errmsg); + return NULL; + } + return obj; +} + -- cgit v1.2.3-59-g8ed1b From 5f394f20bbdc25d508feaf362768e762f5f7c922 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 08:29:31 +0100 Subject: BUG ++ --- doc/TODO.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/TODO.txt b/doc/TODO.txt index af45746..2525eef 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -13,6 +13,9 @@ it seems to be always the same node numbers that gets this wrong edge * BUG: vertices / vertices text fight for being on top. use evas layers ? add 500 edges to reproduce, and watch the nodes +* BUG: layer stacking is wrong, edges end up on top of nodes, despite +eg->split_vertice_edge + * BUG: EGRAPH_LAYOUT_FRUCHTERMANREINGOLD is broken when adding many edges * speed: evas_object_rectangles -- cgit v1.2.3-59-g8ed1b From a2ad51934557537f5da9dcce8980c7bb169394bf Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 08:30:42 +0100 Subject: add egraph_vertice_send_blob() to send a graphical blob from vertice a to vertice b. add theming for this too. add a way to test it from demoapp. --- Egraph.h | 9 +++++++++ data/blob.png | Bin 0 -> 3649 bytes egraph.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ egraph.edc | 30 ++++++++++++++++++++++++++++++ examples/demoapp.c | 25 +++++++++++++++++++++++-- 5 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 data/blob.png diff --git a/Egraph.h b/Egraph.h index f9474b2..4ec39f8 100644 --- a/Egraph.h +++ b/Egraph.h @@ -184,3 +184,12 @@ void egraph_vertice_del(Evas_Object *obj, Egraph_Vertice *v); void egraph_vertice_rename(Evas_Object *obj, Egraph_Vertice *v, const char *name); +/** + * Send a blob from vertice to vertice + * + * A blob is a visual object that will move quickly from the first node to the + * second node. + */ +void egraph_vertice_send_blob(Evas_Object *obj, + Egraph_Vertice *a, Egraph_Vertice *b, + int size, u_int32_t color); diff --git a/data/blob.png b/data/blob.png new file mode 100644 index 0000000..96e4aff Binary files /dev/null and b/data/blob.png differ diff --git a/egraph.c b/egraph.c index cb4d8e6..9c767c4 100644 --- a/egraph.c +++ b/egraph.c @@ -28,6 +28,7 @@ static void _vertice_del(Egraph *eg, Egraph_Vertice *v); static void _v2_update(Egraph *eg); static void _v3_update(Egraph *eg); static void _coords2_copy(Egraph *eg); +static void _cb_blob_arrived(void *data, Efx_Map_Data *e, Evas_Object *obj); static void _layouting_schedule(Egraph *eg); static Eina_Bool _cb_layouting_start(void *data); static void _cb_layouting_run(void *data, Ecore_Thread *thread); @@ -588,6 +589,50 @@ egraph_vertice_rename(Evas_Object *obj, Egraph_Vertice *v, const char *name) } } +void +_color_int_to_rgb(u_int32_t color, int *r, int *g , int *b) +{ + *r = (color & 0xFF000000) >> 24; + *g = (color & 0x00FF0000) >> 16; + *b = (color & 0x0000FF00) >> 8; +} + +void +egraph_vertice_send_blob(Evas_Object *obj, + Egraph_Vertice *a, Egraph_Vertice *b, + int size, u_int32_t color) +{ + EGRAPH_DATA_GET(obj, eg); + Evas_Object *blob; + int ax, ay, aw, ah, bx, by, bw, bh; + int cr, cg, cb; + + if (!a->o || !b->o) + return; + evas_object_geometry_get(a->o, &ax, &ay, &aw, &ah); + evas_object_geometry_get(b->o, &bx, &by, &bw, &bh); + _color_int_to_rgb(color, &cr, &cg, &cb); + + blob = _edje_obj_new(eg, "blob"); + if (!blob) + blob = evas_object_rectangle_add(eg->evas); + evas_object_color_set(blob, cr, cg, cb, 255); + evas_object_smart_member_add(blob, eg->obj); + evas_object_stack_above(blob, eg->split_vertice_edge); + evas_object_move(blob, ax+aw/2, ay+ah/2); + evas_object_resize(blob, size, size); + evas_object_show(blob); + + efx_move(blob, EFX_EFFECT_SPEED_SINUSOIDAL, + &(Evas_Point){ bx+bw/2, by+bw/2 }, 0.4, _cb_blob_arrived, b); +} + +static void +_cb_blob_arrived(void *data, Efx_Map_Data *e, Evas_Object *obj) +{ + evas_object_del(obj); +} + static void _layouting_schedule(Egraph *eg) { diff --git a/egraph.edc b/egraph.edc index f411674..6b80e6c 100644 --- a/egraph.edc +++ b/egraph.edc @@ -59,4 +59,34 @@ collections { } } } + group { + name: "blob"; + max: 700 700; + min: 700 700; + images { + image: "data/blob.png" COMP; + } + parts { + part { + name: "image"; + type: IMAGE; + description { + state: "default" 0.0; + max: 50 50; + min: 3 3; + image{ + normal: "data/blob.png"; + } + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + } + description { + state: "down-state" 1.0; + inherit: "default" 0.0; + rel1.relative: 0.0 1.0; + rel2.relative: 0.0 0.0; + } + } + } + } } diff --git a/examples/demoapp.c b/examples/demoapp.c index 6f012a3..163f09f 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -72,6 +72,25 @@ _cb_del_edges(void *data, Evas_Object *obj, void *event_info) _vertice_list = eina_list_free(_vertice_list); } +static void +_cb_send_100blobs(void *data, Evas_Object *obj, void *event_info) +{ + Egraph_Vertice *a, *b; + int count, ran, i; + + count = eina_list_count(_vertice_list); + if (!count) + return; + + for (i=0; i<100; i++) { + ran = random() % count; + a = eina_list_nth(_vertice_list, ran); + ran = random() % count; + b = eina_list_nth(_vertice_list, ran); + egraph_vertice_send_blob(_egraph, a, b, 5, 0xFF000000); + } +} + static void _cb_show_nodes(void *data, Evas_Object *obj, void *event_info) { @@ -205,6 +224,8 @@ elm_main(int argc, char **argv) _cb_add_500edges, NULL); elm_toolbar_item_append(tb, "edit-delete", "Delete all", _cb_del_edges, NULL); + elm_toolbar_item_append(tb, "object-rotate-right", "Send 100 blobs", + _cb_send_100blobs, NULL); elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); lb = elm_label_add(win); elm_object_text_set(lb, "Layout"); @@ -304,9 +325,9 @@ elm_main(int argc, char **argv) evas_object_show(lb); elm_object_part_content_set(panes, "right", lb); - evas_object_resize(win, 150, 150); + evas_object_resize(win, 150, 150); // XXX workaround elm sizing issue evas_object_show(win); - evas_object_resize(win, 850, 600); + evas_object_resize(win, 850, 650); evas_object_show(win); _egraph = egraph; _mainwin = win; -- cgit v1.2.3-59-g8ed1b From c5f73d91d479892df30ca1e25e594ee2689d61cf Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 10:30:44 +0100 Subject: fixup stacking --- egraph.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/egraph.c b/egraph.c index 9c767c4..f1cd73b 100644 --- a/egraph.c +++ b/egraph.c @@ -121,7 +121,6 @@ egraph_new(Evas *evas, int directed) eg->obj = obj; rect = evas_object_rectangle_add(eg->evas); evas_object_color_set(rect, 0, 0, 0, 0); - evas_object_show(rect); // XXX evas_object_smart_member_add(rect, obj); eg->split_vertice_edge = rect; @@ -496,6 +495,7 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) evas_object_color_set(text, 200, 255, 0, 255); evas_object_text_font_set(text, "Vera-Bold", VERTICE_TEXT_H); evas_object_smart_member_add(text, eg->obj); + evas_object_stack_above(text, eg->split_vertice_edge); v->o_text = text; if (v->name) @@ -1061,9 +1061,6 @@ _reposition(Egraph *eg, int no_animation) &(Evas_Point){ x, y }, 0.5, NULL, NULL); else evas_object_move(v->o, x, y); - if (eg->display_names) { - evas_object_raise(v->o_text); - } if (v->new) { if (eg->display_vertices) evas_object_show(v->o); -- cgit v1.2.3-59-g8ed1b From 7b191475d3122f0e2bda9eed061610e6d920c75b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Tue, 11 Dec 2012 10:30:50 +0100 Subject: fix blob position --- egraph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index f1cd73b..fd50878 100644 --- a/egraph.c +++ b/egraph.c @@ -619,12 +619,12 @@ egraph_vertice_send_blob(Evas_Object *obj, evas_object_color_set(blob, cr, cg, cb, 255); evas_object_smart_member_add(blob, eg->obj); evas_object_stack_above(blob, eg->split_vertice_edge); - evas_object_move(blob, ax+aw/2, ay+ah/2); + evas_object_move(blob, ax, ay); evas_object_resize(blob, size, size); evas_object_show(blob); efx_move(blob, EFX_EFFECT_SPEED_SINUSOIDAL, - &(Evas_Point){ bx+bw/2, by+bw/2 }, 0.4, _cb_blob_arrived, b); + &(Evas_Point){ bx, by }, 0.6, _cb_blob_arrived, b); } static void -- cgit v1.2.3-59-g8ed1b From 4d6e7995544e0e96b9e5418d8c4f2a0b74c25641 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Wed, 12 Dec 2012 19:45:32 +0100 Subject: keep blobs in a list of blobs to be received by a vertice. update destination of the blob when the vertice is moving. --- Egraph.h | 1 + egraph.c | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Egraph.h b/Egraph.h index 4ec39f8..c620f85 100644 --- a/Egraph.h +++ b/Egraph.h @@ -61,6 +61,7 @@ struct Egraph_Vertice { int o_usetheme; Evas_Object *o_text; Eina_List *edges; + Eina_List *blobs; void *data; u_int new : 1; u_int v2_new : 1; diff --git a/egraph.c b/egraph.c index fd50878..34b1aa8 100644 --- a/egraph.c +++ b/egraph.c @@ -29,6 +29,8 @@ static void _v2_update(Egraph *eg); static void _v3_update(Egraph *eg); static void _coords2_copy(Egraph *eg); static void _cb_blob_arrived(void *data, Efx_Map_Data *e, Evas_Object *obj); +static void _blob_send(Evas_Object *blob, + Egraph_Vertice *v, Evas_Coord x, Evas_Coord y); static void _layouting_schedule(Egraph *eg); static Eina_Bool _cb_layouting_start(void *data); static void _cb_layouting_run(void *data, Ecore_Thread *thread); @@ -622,17 +624,28 @@ egraph_vertice_send_blob(Evas_Object *obj, evas_object_move(blob, ax, ay); evas_object_resize(blob, size, size); evas_object_show(blob); - - efx_move(blob, EFX_EFFECT_SPEED_SINUSOIDAL, - &(Evas_Point){ bx, by }, 0.6, _cb_blob_arrived, b); + b->blobs = eina_list_append(b->blobs, blob); + _blob_send(blob, b, bx, by); } static void _cb_blob_arrived(void *data, Efx_Map_Data *e, Evas_Object *obj) { + Egraph_Vertice *v; + + v = data; + v->blobs = eina_list_remove(v->blobs, obj); evas_object_del(obj); } +static void +_blob_send(Evas_Object *blob, Egraph_Vertice *v, Evas_Coord x, Evas_Coord y) +{ + printf("blob_send %d %d\n", x, y); + efx_move(blob, EFX_EFFECT_SPEED_SINUSOIDAL, + &(Evas_Point){ x, y }, 0.6, _cb_blob_arrived, v); +} + static void _layouting_schedule(Egraph *eg) { @@ -1010,6 +1023,8 @@ static void _reposition(Egraph *eg, int no_animation) { Egraph_Vertice *v; + Evas_Object *blob; + Eina_List *l; u_int32_t id; float gw_min, gw_max, gh_min, gh_max, factor_w, factor_h; float x, y; @@ -1056,11 +1071,14 @@ _reposition(Egraph *eg, int no_animation) printf(" inobj: %6.3f %6.3f\n", x, y); v = eina_hash_find(eg->vertices, &id); - if (eg->use_animations && !no_animation) + if (eg->use_animations && !no_animation) { efx_move(v->o, EFX_EFFECT_SPEED_DECELERATE, &(Evas_Point){ x, y }, 0.5, NULL, NULL); + } else evas_object_move(v->o, x, y); + EINA_LIST_FOREACH(v->blobs, l, blob) + _blob_send(blob, v, x, y); if (v->new) { if (eg->display_vertices) evas_object_show(v->o); -- cgit v1.2.3-59-g8ed1b From 74fb22566830f0cd84289972c8933166eba10f04 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Wed, 12 Dec 2012 19:46:22 +0100 Subject: add a button to add an alone node --- examples/demoapp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/examples/demoapp.c b/examples/demoapp.c index 163f09f..e87a218 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -72,6 +72,21 @@ _cb_del_edges(void *data, Evas_Object *obj, void *event_info) _vertice_list = eina_list_free(_vertice_list); } +static void +_cb_add_node(void *data, Evas_Object *obj, void *event_info) +{ + Egraph_Vertice *v; + char buf[64]; + + if (!_egraph) + return; + + v = egraph_vertice_add(_egraph, NULL, NULL); + snprintf(buf, sizeof(buf), "%d", v->id); + egraph_vertice_rename(_egraph, v, buf); + _vertice_list = eina_list_append(_vertice_list, v); +} + static void _cb_send_100blobs(void *data, Evas_Object *obj, void *event_info) { @@ -224,6 +239,8 @@ elm_main(int argc, char **argv) _cb_add_500edges, NULL); elm_toolbar_item_append(tb, "edit-delete", "Delete all", _cb_del_edges, NULL); + elm_toolbar_item_append(tb, "object-rotate-right", "Add 1 node alone", + _cb_add_node, NULL); elm_toolbar_item_append(tb, "object-rotate-right", "Send 100 blobs", _cb_send_100blobs, NULL); elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); -- cgit v1.2.3-59-g8ed1b From f054a20a2e68e4d18f3f0f532bb743f8d729b67f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Wed, 12 Dec 2012 19:51:16 +0100 Subject: bigger window --- examples/demoapp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/demoapp.c b/examples/demoapp.c index e87a218..a998a54 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -344,7 +344,7 @@ elm_main(int argc, char **argv) evas_object_resize(win, 150, 150); // XXX workaround elm sizing issue evas_object_show(win); - evas_object_resize(win, 850, 650); + evas_object_resize(win, 950, 715); evas_object_show(win); _egraph = egraph; _mainwin = win; -- cgit v1.2.3-59-g8ed1b From c983ce2365fb41d72dd65122294f591dcb2688a7 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Wed, 12 Dec 2012 19:51:44 +0100 Subject: better button order --- examples/demoapp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/demoapp.c b/examples/demoapp.c index a998a54..d3e6b58 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -237,10 +237,10 @@ elm_main(int argc, char **argv) _cb_add_50edges, NULL); elm_toolbar_item_append(tb, "object-rotate-right", "Add 500 edges", _cb_add_500edges, NULL); - elm_toolbar_item_append(tb, "edit-delete", "Delete all", - _cb_del_edges, NULL); elm_toolbar_item_append(tb, "object-rotate-right", "Add 1 node alone", _cb_add_node, NULL); + elm_toolbar_item_append(tb, "edit-delete", "Delete all", + _cb_del_edges, NULL); elm_toolbar_item_append(tb, "object-rotate-right", "Send 100 blobs", _cb_send_100blobs, NULL); elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); -- cgit v1.2.3-59-g8ed1b From da6b1c6d00626db09d8a4e29b4cfe7904753b0f0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 02:05:47 +0100 Subject: add functions to create vertices groups and edges types. add button to test this in demoapp. --- Egraph.h | 28 ++++++++++++++++++++++++++++ egraph.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ examples/demoapp.c | 26 ++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/Egraph.h b/Egraph.h index c620f85..5db3b78 100644 --- a/Egraph.h +++ b/Egraph.h @@ -63,6 +63,7 @@ struct Egraph_Vertice { Eina_List *edges; Eina_List *blobs; void *data; + Eina_List *group_vertices; /* used if the vertice is a group */ u_int new : 1; u_int v2_new : 1; u_int v2_del : 1; @@ -73,6 +74,7 @@ struct Egraph_Vertice { struct Egraph_Edge { Egraph_Vertice *a; Egraph_Vertice *b; + char *type; Evas_Object *o; int o_usetheme; void *data; @@ -152,6 +154,12 @@ Egraph_Edge *egraph_edge_add(Evas_Object *obj, */ void egraph_edge_del(Evas_Object *obj, Egraph_Edge *e); +/** + * Sets the type of an edge, to make it appear differently in the graph, + * depending on theme + */ +void egraph_edge_type_set(Evas_Object *obj, + Egraph_Edge *e, const char *type); /** * Finds if an edge exists between 2 vertices */ @@ -194,3 +202,23 @@ void egraph_vertice_rename(Evas_Object *obj, Egraph_Vertice *v, void egraph_vertice_send_blob(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, int size, u_int32_t color); + +/** + * Add a group of vertices, for later attaching nodes to it. + * + * The group is represented by an Egraph_Vertice with special properties. + */ +Egraph_Vertice *egraph_group_add(Evas_Object *obj, + const char *name, void *data); + +/** + * Attach a vertice to a group + */ +int egraph_group_vertice_attach(Evas_Object *obj, + Egraph_Vertice *group, Egraph_Vertice *v); + +/** + * Detach a vertice from a group + */ +void egraph_group_vertice_detach(Evas_Object *obj, + Egraph_Vertice *group, Egraph_Vertice *v); diff --git a/egraph.c b/egraph.c index 34b1aa8..98c87ee 100644 --- a/egraph.c +++ b/egraph.c @@ -19,6 +19,7 @@ static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y); static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); static void _edge_v2_add(Egraph *eg, Egraph_Edge *e); static void _edge_add(Egraph *eg, Egraph_Edge *e); +static void _edge_type_update(Egraph *eg, Egraph_Edge *e); static void _edge_v2_del(Egraph *eg, Egraph_Edge *e); static void _edge_del(Egraph *eg, Egraph_Edge *e); static void _vertice_v2_add(Egraph *eg, Egraph_Vertice *v); @@ -354,11 +355,30 @@ _edge_add(Egraph *eg, Egraph_Edge *e) evas_object_smart_member_add(eobj, eg->obj); evas_object_stack_below(eobj, eg->split_vertice_edge); e->o = eobj; + _edge_type_update(eg, e); e->a->edges = eina_list_append(e->a->edges, e); e->b->edges = eina_list_append(e->b->edges, e); } +void +egraph_edge_type_set(Evas_Object *obj, Egraph_Edge *e, const char *type) +{ + EGRAPH_DATA_GET(obj, eg); + + if (e->type) + free(e->type); + e->type = strndup(type, 30); + _edge_type_update(eg, e); +} + +static void +_edge_type_update(Egraph *eg, Egraph_Edge *e) +{ + if (eg->theme_edges && e->o); + edje_object_signal_emit(e->o, e->type, "type-set"); +} + void egraph_edge_del(Evas_Object *obj, Egraph_Edge *e) { @@ -1130,3 +1150,34 @@ _edje_obj_new(Egraph *eg, char *group) return obj; } +Egraph_Vertice * +egraph_group_add(Evas_Object *obj, const char *name, void *data) +{ + Egraph_Vertice *g; + + g = egraph_vertice_add(obj, name, data); + return g; +} + +int +egraph_group_vertice_attach(Evas_Object *obj, + Egraph_Vertice *group, Egraph_Vertice *v) +{ + Egraph_Edge *e; + + group->group_vertices = eina_list_append(group->group_vertices, v); + e = egraph_edge_add(obj, group, v, NULL); + egraph_edge_type_set(obj, e, "group"); + return 1; +} + +void +egraph_group_vertice_detach(Evas_Object *obj, + Egraph_Vertice *group, Egraph_Vertice *v) +{ + Egraph_Edge *e; + + group->group_vertices = eina_list_remove(group->group_vertices, v); + e = egraph_edge_find(obj, group, v); + egraph_edge_del(obj, e); +} diff --git a/examples/demoapp.c b/examples/demoapp.c index d3e6b58..2b37933 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -106,6 +106,30 @@ _cb_send_100blobs(void *data, Evas_Object *obj, void *event_info) } } +static void +_cb_add_10n_group(void *data, Evas_Object *obj, void *event_info) +{ + Egraph_Vertice *group, *v; + char buf[64]; + int i; + + if (!_egraph) + return; + + group = egraph_group_add(_egraph, NULL, NULL); + snprintf(buf, sizeof(buf), "%d-group", group->id); + egraph_vertice_rename(_egraph, group, buf); + _vertice_list = eina_list_append(_vertice_list, group); + for (i=0; i<10; i++) { + v = egraph_vertice_add(_egraph, NULL, NULL); + snprintf(buf, sizeof(buf), "%d-child(%d)", v->id, group->id); + egraph_vertice_rename(_egraph, v, buf); + egraph_group_vertice_attach(_egraph, group, v); + _vertice_list = eina_list_append(_vertice_list, v); + } +} + + static void _cb_show_nodes(void *data, Evas_Object *obj, void *event_info) { @@ -243,6 +267,8 @@ elm_main(int argc, char **argv) _cb_del_edges, NULL); elm_toolbar_item_append(tb, "object-rotate-right", "Send 100 blobs", _cb_send_100blobs, NULL); + elm_toolbar_item_append(tb, "object-rotate-right", "Add a 10n group", + _cb_add_10n_group, NULL); elm_toolbar_item_separator_set(elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL), EINA_FALSE); lb = elm_label_add(win); elm_object_text_set(lb, "Layout"); -- cgit v1.2.3-59-g8ed1b From 603e7cb27dc269d2cd74ed3cda3b4853e89b4327 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 02:09:18 +0100 Subject: expand the toolbar in demoapp if not enough space to display it --- examples/demoapp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/demoapp.c b/examples/demoapp.c index 2b37933..009bed2 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -247,7 +247,7 @@ elm_main(int argc, char **argv) tb = elm_toolbar_add(win); elm_toolbar_homogeneous_set(tb, EINA_FALSE); elm_toolbar_horizontal_set(tb, EINA_FALSE); - elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_MENU); + elm_toolbar_shrink_mode_set(tb, ELM_TOOLBAR_SHRINK_EXPAND); elm_toolbar_select_mode_set(tb, ELM_OBJECT_SELECT_MODE_ALWAYS); elm_toolbar_transverse_expanded_set(tb, EINA_TRUE); elm_object_style_set(tb, "item_centered"); -- cgit v1.2.3-59-g8ed1b From 754a4b6f25c497b1e3d7688512976d0c2f46e7cb Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 02:50:00 +0100 Subject: add vertice type handling, and fix _edge_type_update() --- Egraph.h | 8 ++++++++ egraph.c | 31 +++++++++++++++++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/Egraph.h b/Egraph.h index 5db3b78..d3b1458 100644 --- a/Egraph.h +++ b/Egraph.h @@ -57,6 +57,7 @@ struct Egraph { struct Egraph_Vertice { u_int32_t id; char *name; + char *type; Evas_Object *o; int o_usetheme; Evas_Object *o_text; @@ -194,6 +195,13 @@ void egraph_vertice_rename(Evas_Object *obj, Egraph_Vertice *v, const char *name); /** + * Sets the type of a vertice, to make it appear differently in the graph, + * depending on theme + */ +void +egraph_vertice_type_set(Evas_Object *obj, Egraph_Vertice *v, const char *type); + + /** * Send a blob from vertice to vertice * * A blob is a visual object that will move quickly from the first node to the diff --git a/egraph.c b/egraph.c index 98c87ee..b9ca4cf 100644 --- a/egraph.c +++ b/egraph.c @@ -25,6 +25,7 @@ static void _edge_del(Egraph *eg, Egraph_Edge *e); static void _vertice_v2_add(Egraph *eg, Egraph_Vertice *v); static void _vertice_add(Egraph *eg, Egraph_Vertice *v); static void _vertice_v2_del(Egraph *eg, Egraph_Vertice *v); +static void _vertice_type_update(Egraph *eg, Egraph_Vertice *v); static void _vertice_del(Egraph *eg, Egraph_Vertice *v); static void _v2_update(Egraph *eg); static void _v3_update(Egraph *eg); @@ -375,8 +376,11 @@ egraph_edge_type_set(Evas_Object *obj, Egraph_Edge *e, const char *type) static void _edge_type_update(Egraph *eg, Egraph_Edge *e) { + if (!e->type) + return; + if (eg->theme_edges && e->o); - edje_object_signal_emit(e->o, e->type, "type-set"); + edje_object_signal_emit(e->o, e->type, ""); } void @@ -511,6 +515,7 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) evas_object_resize(vobj, VERTICE_OBJ_W, VERTICE_OBJ_H); evas_object_event_callback_add(vobj, EVAS_CALLBACK_MOVE, _cb_vertice_move, v); v->o = vobj; + _vertice_type_update(eg, v); text = evas_object_text_add(eg->evas); evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); @@ -590,6 +595,27 @@ _vertice_del(Egraph *eg, Egraph_Vertice *v) free(v); } +void +egraph_vertice_type_set(Evas_Object *obj, Egraph_Vertice *v, const char *type) +{ + EGRAPH_DATA_GET(obj, eg); + + if (v->type) + free(v->type); + v->type = strndup(type, 30); + _vertice_type_update(eg, v); +} + +static void +_vertice_type_update(Egraph *eg, Egraph_Vertice *v) +{ + if (!v->type) + return; + + if (eg->theme_edges && v->o); + edje_object_signal_emit(v->o, v->type, ""); +} + void egraph_vertice_rename(Evas_Object *obj, Egraph_Vertice *v, const char *name) { @@ -1156,6 +1182,7 @@ egraph_group_add(Evas_Object *obj, const char *name, void *data) Egraph_Vertice *g; g = egraph_vertice_add(obj, name, data); + egraph_vertice_type_set(obj, g, "become_group"); return g; } @@ -1167,7 +1194,7 @@ egraph_group_vertice_attach(Evas_Object *obj, group->group_vertices = eina_list_append(group->group_vertices, v); e = egraph_edge_add(obj, group, v, NULL); - egraph_edge_type_set(obj, e, "group"); + egraph_edge_type_set(obj, e, "become_group"); return 1; } -- cgit v1.2.3-59-g8ed1b From 6525a75df890c048e89412de0e0bc5affa537b4c Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 02:53:42 +0100 Subject: fix potential unsafe list deletion in _vertice_del() --- egraph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index b9ca4cf..000359c 100644 --- a/egraph.c +++ b/egraph.c @@ -573,10 +573,10 @@ static void _vertice_del(Egraph *eg, Egraph_Vertice *v) { Egraph_Edge *e; - Eina_List *l; + Eina_List *l, *lprev; int pos; - EINA_LIST_FOREACH(eg->edges, l, e) + EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) if (e->a == v || e->b == v) _edge_del(eg, e); -- cgit v1.2.3-59-g8ed1b From 4b3f7b998e499789a27d1ebb969912b1fb025e9d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 02:57:08 +0100 Subject: fix memleak and delete blobs in _vertice_del() --- egraph.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/egraph.c b/egraph.c index 000359c..c6da953 100644 --- a/egraph.c +++ b/egraph.c @@ -574,16 +574,22 @@ _vertice_del(Egraph *eg, Egraph_Vertice *v) { Egraph_Edge *e; Eina_List *l, *lprev; + Evas_Object *blob; int pos; EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) if (e->a == v || e->b == v) _edge_del(eg, e); + eina_list_free(v->edges); pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, v->id); igraph_delete_vertices(&eg->graph, igraph_vss_1(pos)); eg->graph_vcount--; + EINA_LIST_FOREACH(v->blobs, l, blob) + evas_object_del(blob); + eina_list_free(v->blobs); + evas_object_del(v->o); if (v->o_text) evas_object_del(v->o_text); -- cgit v1.2.3-59-g8ed1b From 56f227372d1743edc2699a3fb5eabb35ab59ae48 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 02:59:15 +0100 Subject: rename vertice->blobs to vertice->blobs_incoming for clarity --- Egraph.h | 2 +- egraph.c | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Egraph.h b/Egraph.h index d3b1458..14dddc2 100644 --- a/Egraph.h +++ b/Egraph.h @@ -62,7 +62,7 @@ struct Egraph_Vertice { int o_usetheme; Evas_Object *o_text; Eina_List *edges; - Eina_List *blobs; + Eina_List *blobs_incoming; void *data; Eina_List *group_vertices; /* used if the vertice is a group */ u_int new : 1; diff --git a/egraph.c b/egraph.c index c6da953..4034ea6 100644 --- a/egraph.c +++ b/egraph.c @@ -586,9 +586,9 @@ _vertice_del(Egraph *eg, Egraph_Vertice *v) igraph_delete_vertices(&eg->graph, igraph_vss_1(pos)); eg->graph_vcount--; - EINA_LIST_FOREACH(v->blobs, l, blob) + EINA_LIST_FOREACH(v->blobs_incoming, l, blob) evas_object_del(blob); - eina_list_free(v->blobs); + eina_list_free(v->blobs_incoming); evas_object_del(v->o); if (v->o_text) @@ -676,7 +676,7 @@ egraph_vertice_send_blob(Evas_Object *obj, evas_object_move(blob, ax, ay); evas_object_resize(blob, size, size); evas_object_show(blob); - b->blobs = eina_list_append(b->blobs, blob); + b->blobs_incoming = eina_list_append(b->blobs_incoming, blob); _blob_send(blob, b, bx, by); } @@ -686,7 +686,7 @@ _cb_blob_arrived(void *data, Efx_Map_Data *e, Evas_Object *obj) Egraph_Vertice *v; v = data; - v->blobs = eina_list_remove(v->blobs, obj); + v->blobs_incoming = eina_list_remove(v->blobs_incoming, obj); evas_object_del(obj); } @@ -1129,7 +1129,7 @@ _reposition(Egraph *eg, int no_animation) } else evas_object_move(v->o, x, y); - EINA_LIST_FOREACH(v->blobs, l, blob) + EINA_LIST_FOREACH(v->blobs_incoming, l, blob) _blob_send(blob, v, x, y); if (v->new) { if (eg->display_vertices) -- cgit v1.2.3-59-g8ed1b From dd21438b962e3c4a0ae72a202e0dd0e1b0f4bdab Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 03:00:40 +0100 Subject: add programs in vertice and edge parts to handle signals ordering to change state --- egraph.edc | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/egraph.edc b/egraph.edc index 6b80e6c..0a62e28 100644 --- a/egraph.edc +++ b/egraph.edc @@ -21,13 +21,21 @@ collections { rel2.relative: 1.0 1.0; } description { - state: "down-state" 1.0; + state: "group" 1.0; inherit: "default" 0.0; - rel1.relative: 0.0 1.0; - rel2.relative: 0.0 0.0; + color: 255 255 255 50; } } } + programs { + program { + name: "state_group"; + signal: "become_group"; + action: STATE_SET "group" 0.0; + target: "image"; + transition: DECELERATE 0.5; + } + } } group { name: "edge"; @@ -51,13 +59,21 @@ collections { rel2.relative: 1.0 1.0; } description { - state: "down-state" 1.0; + state: "group" 1.0; inherit: "default" 0.0; - rel1.relative: 0.0 1.0; - rel2.relative: 0.0 0.0; + color: 255 255 255 50; } } } + programs { + program { + name: "state_group"; + signal: "become_group"; + action: STATE_SET "group" 0.0; + target: "image"; + transition: DECELERATE 0.5; + } + } } group { name: "blob"; -- cgit v1.2.3-59-g8ed1b From e2d6117b68929b1570bb7fad63104203cd243b79 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 03:05:40 +0100 Subject: place groups in a different list so that they do not get sected when adding edges --- examples/demoapp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/demoapp.c b/examples/demoapp.c index 009bed2..3b56dd4 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -6,6 +6,7 @@ Evas_Object *_mainwin; Evas_Object *_egraph; Eina_List *_vertice_list = NULL; +Eina_List *_group_list = NULL; static void _cb_add_edge(void *data, Evas_Object *obj, void *event_info) @@ -68,8 +69,11 @@ _cb_del_edges(void *data, Evas_Object *obj, void *event_info) EINA_LIST_FOREACH(_vertice_list, l, v) egraph_vertice_del(_egraph, v); + EINA_LIST_FOREACH(_group_list, l, v) + egraph_vertice_del(_egraph, v); _vertice_list = eina_list_free(_vertice_list); + _group_list = eina_list_free(_group_list); } static void @@ -119,7 +123,7 @@ _cb_add_10n_group(void *data, Evas_Object *obj, void *event_info) group = egraph_group_add(_egraph, NULL, NULL); snprintf(buf, sizeof(buf), "%d-group", group->id); egraph_vertice_rename(_egraph, group, buf); - _vertice_list = eina_list_append(_vertice_list, group); + _group_list = eina_list_append(_group_list, group); for (i=0; i<10; i++) { v = egraph_vertice_add(_egraph, NULL, NULL); snprintf(buf, sizeof(buf), "%d-child(%d)", v->id, group->id); -- cgit v1.2.3-59-g8ed1b From b50daaf4b5eddaad5f48634ff3037ca5700e136a Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 06:23:29 +0100 Subject: fix bug when we delete vertices/edges that have just been added. added checks in vertice/edge[_v2]_del for v2_new / v3_new. --- egraph.c | 64 ++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 28 deletions(-) diff --git a/egraph.c b/egraph.c index 4034ea6..3fe0877 100644 --- a/egraph.c +++ b/egraph.c @@ -407,10 +407,12 @@ _edge_v2_del(Egraph *eg, Egraph_Edge *e) e->v2_del = 1; e->v3_del = 0; - a_pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, e->a->id); - b_pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, e->b->id); - igraph_es_pairs_small(&es, eg->graph_directed, a_pos, b_pos, -1); - igraph_delete_edges(&eg->graph2, es); + if (!e->v3_new) { + a_pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, e->a->id); + b_pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, e->b->id); + igraph_es_pairs_small(&es, eg->graph_directed, a_pos, b_pos, -1); + igraph_delete_edges(&eg->graph2, es); + } } static void @@ -419,16 +421,18 @@ _edge_del(Egraph *eg, Egraph_Edge *e) igraph_es_t es; int a_pos, b_pos; - a_pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, e->a->id); - b_pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, e->b->id); - igraph_es_pairs_small(&es, eg->graph_directed, a_pos, b_pos, -1); - igraph_delete_edges(&eg->graph, es); + if (!e->v3_new && !e->v2_new) { + a_pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, e->a->id); + b_pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, e->b->id); + igraph_es_pairs_small(&es, eg->graph_directed, a_pos, b_pos, -1); + igraph_delete_edges(&eg->graph, es); - e->a->edges = eina_list_remove(e->a->edges, e); - e->b->edges = eina_list_remove(e->b->edges, e); - evas_object_del(e->o); + e->a->edges = eina_list_remove(e->a->edges, e); + e->b->edges = eina_list_remove(e->b->edges, e); + evas_object_del(e->o); - eg->edges = eina_list_remove(eg->edges, e); + eg->edges = eina_list_remove(eg->edges, e); + } free(e); } @@ -564,9 +568,11 @@ _vertice_v2_del(Egraph *eg, Egraph_Vertice *v) if (e->a == v || e->b == v) _edge_v2_del(eg, e); - pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, v->id); - igraph_delete_vertices(&eg->graph2, igraph_vss_1(pos)); - eg->graph2_vcount--; + if (!v->v3_new) { + pos = _igraph_query_vid(&eg->graph2, eg->graph2_vcount, v->id); + igraph_delete_vertices(&eg->graph2, igraph_vss_1(pos)); + eg->graph2_vcount--; + } } static void @@ -577,22 +583,24 @@ _vertice_del(Egraph *eg, Egraph_Vertice *v) Evas_Object *blob; int pos; - EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) - if (e->a == v || e->b == v) - _edge_del(eg, e); - eina_list_free(v->edges); + if (!v->v3_new && !v->v2_new) { + EINA_LIST_FOREACH_SAFE(eg->edges, l, lprev, e) + if (e->a == v || e->b == v) + _edge_del(eg, e); + eina_list_free(v->edges); - pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, v->id); - igraph_delete_vertices(&eg->graph, igraph_vss_1(pos)); - eg->graph_vcount--; + pos = _igraph_query_vid(&eg->graph, eg->graph_vcount, v->id); + igraph_delete_vertices(&eg->graph, igraph_vss_1(pos)); + eg->graph_vcount--; - EINA_LIST_FOREACH(v->blobs_incoming, l, blob) - evas_object_del(blob); - eina_list_free(v->blobs_incoming); + EINA_LIST_FOREACH(v->blobs_incoming, l, blob) + evas_object_del(blob); + eina_list_free(v->blobs_incoming); - evas_object_del(v->o); - if (v->o_text) - evas_object_del(v->o_text); + evas_object_del(v->o); + if (v->o_text) + evas_object_del(v->o_text); + } eina_hash_del(eg->vertices, &v->id, NULL); eg->vertices_count--; -- cgit v1.2.3-59-g8ed1b From fe655157f9196ed8f724b51250f250e266c53281 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 06:32:32 +0100 Subject: lockup++ --- doc/bug_lockup_evas.txt | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index e75bf7f..a2eacf0 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -286,3 +286,55 @@ _calc_intra_outer_rect_area (outer=, intra=, intra=, a=..., b=...) + at lib/evas/common/evas_tiler.c:479 +#1 rect_list_add_split_fuzzy (node=0x8ed9c0, rects=0x691668, + accepted_error=) at lib/evas/common/evas_tiler.c:652 +#2 rect_list_add_split_fuzzy_and_merge (node=0x8ed9c0, rects=0x691668, + split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#3 _add_redraw (h=115, w=327, y=203, x=504, rects=0x691668) + at lib/evas/common/evas_tiler.c:956 +#4 evas_common_tilebuf_add_redraw (tb=0x691630, x=504, y=203, w=327, h=115) + at lib/evas/common/evas_tiler.c:986 +#5 0x00007ffff535cb9d in evas_object_render_pre_effect_updates (rects= + 0x688938, eo_obj=, is_v=1, was_v=) + at lib/evas/canvas/evas_object_main.c:356 +#6 0x00007ffff539bbfc in _evas_render_phase1_direct (render_objects=0x9baa60, + active_objects=0x688740, e=, + restack_objects=, delete_objects=) + at lib/evas/canvas/evas_render.c:231 +#7 evas_render_updates_internal (eo_e=0x6886b0, + make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') + at lib/evas/canvas/evas_render.c:1357 +#8 0x00007ffff539dcd7 in _canvas_render_updates (eo_e=, + _pd=, list=) + at lib/evas/canvas/evas_render.c:1795 +#9 0x00007ffff706fa35 in _eo_op_internal (obj=0x6886b0, op_type= + EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe228) at lib/eo/eo.c:363 +#10 0x00007ffff70716cd in _eo_dov_internal (p_list=0x7fffffffe228, op_type= + EO_OP_TYPE_REGULAR, obj=0x6886b0) at lib/eo/eo.c:403 +#11 eo_do_internal (obj=0x6886b0, op_type=op_type@entry=EO_OP_TYPE_REGULAR) + at lib/eo/eo.c:434 +#12 0x00007ffff539dc5f in evas_render_updates (eo_e=) + at lib/evas/canvas/evas_render.c:1779 +#13 0x00007fffe6f7a43a in _ecore_evas_x_render (ee=0x686f30) + at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#14 0x00007ffff6e5e7f1 in _ecore_evas_idle_enter (data=) + at lib/ecore_evas/ecore_evas.c:59 +#15 0x00007ffff50e6019 in _ecore_call_task_cb (data=, + func=) at lib/ecore/ecore_private.h:300 +#16 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#17 0x00007ffff50e862d in _ecore_main_loop_iterate_internal ( + once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1841 +#18 0x00007ffff50e8b27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 +#19 0x000000000040230e in elm_main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:269 +#20 0x0000000000402359 in main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:276 -- cgit v1.2.3-59-g8ed1b From 9bc6c9a9b755c63b456881f24e32cc539af62e9c Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 07:04:46 +0100 Subject: disable efx_move() on blobs when a vertice is repositionned for now --- egraph.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index 3fe0877..492a1c8 100644 --- a/egraph.c +++ b/egraph.c @@ -1083,8 +1083,6 @@ static void _reposition(Egraph *eg, int no_animation) { Egraph_Vertice *v; - Evas_Object *blob; - Eina_List *l; u_int32_t id; float gw_min, gw_max, gh_min, gh_max, factor_w, factor_h; float x, y; @@ -1137,8 +1135,12 @@ _reposition(Egraph *eg, int no_animation) } else evas_object_move(v->o, x, y); + /* XXX fix blob repositionning + Evas_Object *blob; + Eina_List *l; EINA_LIST_FOREACH(v->blobs_incoming, l, blob) _blob_send(blob, v, x, y); + */ if (v->new) { if (eg->display_vertices) evas_object_show(v->o); -- cgit v1.2.3-59-g8ed1b From b67af443fa8263e080f3af9ca66d02f14f300be8 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 08:38:28 +0100 Subject: evas lockup++ --- doc/bug_lockup_evas.txt | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index a2eacf0..b07c089 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -338,3 +338,60 @@ _calc_intra_outer_rect_area (outer=, intra=) at lib/evas/common/evas_tiler.c:653 +653 area = current.area + r.area - intra.area; + +(gdb) bt +#0 rect_list_add_split_fuzzy (node=0x884d70, rects=0x691668, + accepted_error=) at lib/evas/common/evas_tiler.c:653 +#1 rect_list_add_split_fuzzy_and_merge (node=0x884d70, rects=0x691668, + split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#2 _add_redraw (h=12, w=542, y=356, x=118, rects=0x691668) + at lib/evas/common/evas_tiler.c:956 +#3 evas_common_tilebuf_add_redraw (tb=tb@entry=0x691630, x=118, y=356, w=542, + h=12) at lib/evas/common/evas_tiler.c:986 +#4 0x00007fffe6d672ac in _merge_rects (tb=0x691630, r1=, r2= + 0x0, r3=0x0) at modules/evas/engines/software_x11/evas_engine.c:713 +#5 0x00007fffe6d6759b in eng_output_redraws_next_update_get (data=0x691c00, x= + 0x7fffffffe13c, y=0x7fffffffe140, w=0x7fffffffe144, h=0x7fffffffe148, + cx=, cy=0x7fffffffe150, cw=0x7fffffffe154, ch= + 0x7fffffffe158) at modules/evas/engines/software_x11/evas_engine.c:821 +#6 0x00007ffff539bf4f in evas_render_updates_internal (eo_e=0x6886b0, + make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') + at lib/evas/canvas/evas_render.c:1533 +#7 0x00007ffff539dcd7 in _canvas_render_updates (eo_e=, + _pd=, list=) + at lib/evas/canvas/evas_render.c:1795 +#8 0x00007ffff706fa35 in _eo_op_internal (obj=0x6886b0, op_type= + EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe228) at lib/eo/eo.c:363 +#9 0x00007ffff70716cd in _eo_dov_internal (p_list=0x7fffffffe228, op_type= + EO_OP_TYPE_REGULAR, obj=0x6886b0) at lib/eo/eo.c:403 +#10 eo_do_internal (obj=0x6886b0, op_type=op_type@entry=EO_OP_TYPE_REGULAR) + at lib/eo/eo.c:434 +#11 0x00007ffff539dc5f in evas_render_updates (eo_e=) + at lib/evas/canvas/evas_render.c:1779 +#12 0x00007fffe6f7a43a in _ecore_evas_x_render (ee=0x686f30) + at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#13 0x00007ffff6e5e7f1 in _ecore_evas_idle_enter (data=) + at lib/ecore_evas/ecore_evas.c:59 +#14 0x00007ffff50e6019 in _ecore_call_task_cb (data=, + func=) at lib/ecore/ecore_private.h:300 +#15 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#16 0x00007ffff50e847b in _ecore_main_loop_iterate_internal ( + once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#17 0x00007ffff50e8b27 in ecore_main_loop_begin () + at lib/ecore/ecore_main.c:964 +#18 0x000000000040230e in elm_main (argc=1, argv=0x7fffffffe5b8) + at gg_map.c:269 +#19 0x0000000000402359 in main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:276 + + -- cgit v1.2.3-59-g8ed1b From 268f61f8ec38f39f43408fddb3c8dc7c68a1c63b Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 08:38:44 +0100 Subject: oops fix missing edge list remove in _edge_del(), introduced in commit b50daaf4b5eddaad5f48634ff3037ca5700e136a Author: Laurent Ghigonis Date: Thu Dec 13 06:23:29 2012 +0100 fix bug when we delete vertices/edges that have just been added. added checks in vertice/edge[_v2]_del for v2_new / v3_new. egraph.c --- egraph.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index 492a1c8..d02b537 100644 --- a/egraph.c +++ b/egraph.c @@ -430,9 +430,8 @@ _edge_del(Egraph *eg, Egraph_Edge *e) e->a->edges = eina_list_remove(e->a->edges, e); e->b->edges = eina_list_remove(e->b->edges, e); evas_object_del(e->o); - - eg->edges = eina_list_remove(eg->edges, e); } + eg->edges = eina_list_remove(eg->edges, e); free(e); } -- cgit v1.2.3-59-g8ed1b From c7e389e5609f6c4dfd13a67ed2ffaae3cd26d37f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 15:29:38 +0100 Subject: egraph_edge_find() should *not* return edges marked for deletion ! you ugly bitch!!! fix memory corruption in gg_map ! --- egraph.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index d02b537..8ed2845 100644 --- a/egraph.c +++ b/egraph.c @@ -443,8 +443,9 @@ egraph_edge_find(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b) Eina_List *l; EINA_LIST_FOREACH(eg->edges, l, e) - if ((e->a == a && e->b == b) || - (e->a == b && e->b == a)) + if (!(e->v3_del || e->v2_del) && + ((e->a == a && e->b == b) || + (e->a == b && e->b == a))) return e; return NULL; } -- cgit v1.2.3-59-g8ed1b From e802a3d59477c36a234eed2d1e8070f8a8a0d3e1 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 15:48:28 +0100 Subject: evas lockup ++ --- doc/bug_lockup_evas.txt | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index b07c089..6f66266 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -394,4 +394,69 @@ rect_list_add_split_fuzzy (node=0x884d70, rects=0x691668, at gg_map.c:269 #19 0x0000000000402359 in main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:276 +=============================================================================== +2012-12-13_15-32 + +^C 0x7fffe6d61700 (LWP 21696)] +[Thread 0x7fffe6d61700 (LWP 21696) exited] +[New Thread 0x7fffe6d61700 (LWP 21697)] +[Thread 0x7fffe6d61700 (LWP 21697) exited] +[New Thread 0x7fffe6d61700 (LWP 21711)] +[Thread 0x7fffe6d61700 (LWP 21711) exited] +[New Thread 0x7fffe6d61700 (LWP 21712)] +[Thread 0x7fffe6d61700 (LWP 21712) exited] + +Program received signal SIGINT, Interrupt. +rect_list_add_split_fuzzy (node=0xa977b0, rects=0x691668, + accepted_error=) at lib/evas/common/evas_tiler.c:680 +680 else if ((outer.area - area) <= accepted_error) + +(gdb) bt +#0 rect_list_add_split_fuzzy (node=0xa977b0, rects=0x691668, + accepted_error=) at lib/evas/common/evas_tiler.c:680 +#1 rect_list_add_split_fuzzy_and_merge (node=0xa977b0, rects=0x691668, + split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#2 _add_redraw (h=6, w=126, y=110, x=463, rects=0x691668) + at lib/evas/common/evas_tiler.c:956 +#3 evas_common_tilebuf_add_redraw (tb=0x691630, x=463, y=110, w=126, h=6) + at lib/evas/common/evas_tiler.c:986 +#4 0x00007ffff535cb9d in evas_object_render_pre_effect_updates ( + rects=rects@entry=0x688938, eo_obj=eo_obj@entry=0xa83500, is_v=is_v@entry= + 1, was_v=was_v@entry=1) at lib/evas/canvas/evas_object_main.c:356 +#5 0x00007ffff535560d in evas_object_image_render_pre (eo_obj=0xa83500, obj= + 0xa83590) at lib/evas/canvas/evas_object_image.c:3768 +#6 0x00007ffff539bbfc in _evas_render_phase1_direct (render_objects=0xa83500, + active_objects=0x688740, e=, + restack_objects=, delete_objects=) + at lib/evas/canvas/evas_render.c:231 +#7 evas_render_updates_internal (eo_e=0x6886b0, + make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') + at lib/evas/canvas/evas_render.c:1357 +#8 0x00007ffff539dcd7 in _canvas_render_updates (eo_e=, + _pd=, list=) + at lib/evas/canvas/evas_render.c:1795 +#9 0x00007ffff706fa35 in _eo_op_internal (obj=0x6886b0, op_type= + EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe228) at lib/eo/eo.c:363 +#10 0x00007ffff70716cd in _eo_dov_internal (p_list=0x7fffffffe228, op_type= + EO_OP_TYPE_REGULAR, obj=0x6886b0) at lib/eo/eo.c:403 +#11 eo_do_internal (obj=0x6886b0, op_type=op_type@entry=EO_OP_TYPE_REGULAR) + at lib/eo/eo.c:434 +#12 0x00007ffff539dc5f in evas_render_updates (eo_e=) + at lib/evas/canvas/evas_render.c:1779 +#13 0x00007fffe6f7943a in _ecore_evas_x_render (ee=0x686f30) + at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#14 0x00007ffff6e5e7f1 in _ecore_evas_idle_enter (data=) + at lib/ecore_evas/ecore_evas.c:59 +#15 0x00007ffff50e6019 in _ecore_call_task_cb (data=, + func=) at lib/ecore/ecore_private.h:300 +#16 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#17 0x00007ffff50e847b in _ecore_main_loop_iterate_internal ( + once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#18 0x00007ffff50e8b27 in ecore_main_loop_begin () + at lib/ecore/ecore_main.c:964 +#19 0x00000000004022f1 in elm_main (argc=1, argv=0x7fffffffe5b8) + at gg_map.c:273 +#20 0x000000000040233c in main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:280 +(gdb) -- cgit v1.2.3-59-g8ed1b From 04ccd198bbd6b3023d8963bb8c65ee0d6da4181f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 15:48:45 +0100 Subject: err() on calloc failure --- egraph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index 8ed2845..d06d8b0 100644 --- a/egraph.c +++ b/egraph.c @@ -300,7 +300,7 @@ egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, e = calloc(1, sizeof(Egraph_Edge)); if (!e) - return NULL; + err(1, "egraph_edge_add: cannot calloc"); e->v3_new = 1; e->a = a; e->b = b; @@ -463,7 +463,7 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) } v = calloc(1, sizeof(Egraph_Vertice)); if (!v) - return NULL; + err(1, "egraph_vertice_add: cannot calloc"); id = eg->vertices_freeids[eg->vertices_count]; v->id = id; eina_hash_add(eg->vertices, &id, v); -- cgit v1.2.3-59-g8ed1b From ea114e4cc4032c802c33762a269928c63da548af Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 15:49:00 +0100 Subject: add extra check and printf in egraph_edge_del() --- egraph.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/egraph.c b/egraph.c index d06d8b0..4500ba1 100644 --- a/egraph.c +++ b/egraph.c @@ -387,6 +387,12 @@ void egraph_edge_del(Evas_Object *obj, Egraph_Edge *e) { EGRAPH_DATA_GET(obj, eg); + + // XXX DEBUG find mem corrupt, del already del edge + if (!egraph_edge_find(obj, e->a, e->b)) + printf("XXX DEBUG: egraph_edge_del on unknown edge !!!\n"); + if (DEBUG) + printf("egraph_edge_del: %d %d\n", e->a->id, e->b->id); e->v3_del = 1; _layouting_schedule(eg); -- cgit v1.2.3-59-g8ed1b From 011e89ba9ee32d1298984613cc77fcb3223d4e40 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 17:21:57 +0100 Subject: evas lockup+++ --- doc/bug_lockup_evas.txt | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index 6f66266..b7afa30 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -460,3 +460,52 @@ rect_list_add_split_fuzzy (node=0xa977b0, rects=0x691668, at gg_map.c:273 #20 0x000000000040233c in main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:280 (gdb) + + +=============================================================================== +2012-12-13_17-19 + + +rect_list_add_split_fuzzy (node=0xb07d60, rects=0x692668, [0/1873] + accepted_error=) at lib/evas/common/evas_tiler.c:653 +653 area = current.area + r.area - intra.area; +(gdb) bt +#0 rect_list_add_split_fuzzy (node=0xb07d60, rects=0x692668, + accepted_error=) at lib/evas/common/evas_tiler.c:653 +#1 rect_list_add_split_fuzzy_and_merge (node=0xb07d60, rects=0x692668, + split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#2 _add_redraw (h=30, w=79, y=539, x=665, rects=0x692668) + at lib/evas/common/evas_tiler.c:956 +#3 evas_common_tilebuf_add_redraw (tb=0x692630, x=665, y=539, w=79, h=30) + at lib/evas/common/evas_tiler.c:986 +#4 0x00007ffff539bd1c in _evas_render_phase1_direct (render_objects=0xb61c40, + active_objects=0x689740, e=, + restack_objects=, delete_objects=) + at lib/evas/canvas/evas_render.c:257 +#5 evas_render_updates_internal (eo_e=0x6896b0, + make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') + at lib/evas/canvas/evas_render.c:1357 +#6 0x00007ffff539dcd7 in _canvas_render_updates (eo_e=, + _pd=, list=) + at lib/evas/canvas/evas_render.c:1795 +#7 0x00007ffff706fa35 in _eo_op_internal (obj=0x6896b0, op_type= + EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe228) at lib/eo/eo.c:363 +#8 0x00007ffff70716cd in _eo_dov_internal (p_list=0x7fffffffe228, op_type= + EO_OP_TYPE_REGULAR, obj=0x6896b0) at lib/eo/eo.c:403 +#9 eo_do_internal (obj=0x6896b0, op_type=op_type@entry=EO_OP_TYPE_REGULAR) + at lib/eo/eo.c:434 +#10 0x00007ffff539dc5f in evas_render_updates (eo_e=) + at lib/evas/canvas/evas_render.c:1779 +#11 0x00007fffe6f7943a in _ecore_evas_x_render (ee=0x687f30) + at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#12 0x00007ffff6e5e7f1 in _ecore_evas_idle_enter (data=) + at lib/ecore_evas/ecore_evas.c:59 +#13 0x00007ffff50e6019 in _ecore_call_task_cb (data=, + func=) at lib/ecore/ecore_private.h:300 +#14 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#15 0x00007ffff50e847b in _ecore_main_loop_iterate_internal ( + once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#16 0x00007ffff50e8b27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 +#17 0x00000000004025d9 in elm_main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:324 +#18 0x0000000000402624 in main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:331 -- cgit v1.2.3-59-g8ed1b From be0de4a6e06cbf3a9afea6f937ff7f3171d8be0f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 17:38:02 +0100 Subject: introduce egraph_clear() to remove all vertices and edge, and use it in demoapp --- Egraph.h | 5 +++++ egraph.c | 16 ++++++++++++++++ examples/demoapp.c | 6 +----- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Egraph.h b/Egraph.h index 14dddc2..ac70bcc 100644 --- a/Egraph.h +++ b/Egraph.h @@ -91,6 +91,11 @@ struct Egraph_Edge { */ Evas_Object *egraph_new(Evas *evas, int directed); +/** + * Remove all nodes and edges + */ +void egraph_clear(Evas_Object *obj); + /** * Configure egraph to use an edje theme */ diff --git a/egraph.c b/egraph.c index 4500ba1..7cb1e6d 100644 --- a/egraph.c +++ b/egraph.c @@ -164,6 +164,22 @@ err: return NULL; } +void +egraph_clear(Evas_Object *obj) +{ + EGRAPH_DATA_GET(obj, eg); + Eina_Iterator *it; + Egraph_Vertice *v; + void *data; + + it = eina_hash_iterator_tuple_new(eg->vertices); + while (eina_iterator_next(it, &data)) { + Eina_Hash_Tuple *t = data; + v = t->data; + egraph_vertice_del(obj, v); + } +} + void egraph_theme_file_set(Evas_Object *obj, char *path) { diff --git a/examples/demoapp.c b/examples/demoapp.c index 3b56dd4..b9e39ad 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -67,11 +67,7 @@ _cb_del_edges(void *data, Evas_Object *obj, void *event_info) if (!_egraph) return; - EINA_LIST_FOREACH(_vertice_list, l, v) - egraph_vertice_del(_egraph, v); - EINA_LIST_FOREACH(_group_list, l, v) - egraph_vertice_del(_egraph, v); - + egraph_clear(_egraph); _vertice_list = eina_list_free(_vertice_list); _group_list = eina_list_free(_group_list); } -- cgit v1.2.3-59-g8ed1b From 190725fa6e8cfcd85e033361e3df15960bae3189 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 17:40:25 +0100 Subject: fix function name --- examples/demoapp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/demoapp.c b/examples/demoapp.c index b9e39ad..af3211f 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -191,7 +191,7 @@ _cb_use_theme_e(void *data, Evas_Object *obj, void *event_info) } static void -cb_layout_changed(void *data, Evas_Object *obj, void *event_info) +_cb_layout_changed(void *data, Evas_Object *obj, void *event_info) { Elm_Object_Item *it; char *selected; @@ -285,7 +285,7 @@ elm_main(int argc, char **argv) elm_segment_control_item_selected_set(seg_it, EINA_FALSE); seg_it = elm_segment_control_item_add(sc, NULL, "Fruchterman R."); elm_segment_control_item_selected_set(seg_it, EINA_FALSE); - evas_object_smart_callback_add(sc, "changed", cb_layout_changed, NULL); + evas_object_smart_callback_add(sc, "changed", _cb_layout_changed, NULL); evas_object_show(sc); tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", sc); -- cgit v1.2.3-59-g8ed1b From 4f5f93fee7253b3cda65340ce5af45cc1d707969 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 18:12:59 +0100 Subject: make printf conditionnal on DEBUG --- egraph.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/egraph.c b/egraph.c index 7cb1e6d..b56a831 100644 --- a/egraph.c +++ b/egraph.c @@ -723,7 +723,8 @@ _cb_blob_arrived(void *data, Efx_Map_Data *e, Evas_Object *obj) static void _blob_send(Evas_Object *blob, Egraph_Vertice *v, Evas_Coord x, Evas_Coord y) { - printf("blob_send %d %d\n", x, y); + if (DEBUG) + printf("blob_send %d %d\n", x, y); efx_move(blob, EFX_EFFECT_SPEED_SINUSOIDAL, &(Evas_Point){ x, y }, 0.6, _cb_blob_arrived, v); } -- cgit v1.2.3-59-g8ed1b From 6069b190f6b5d1398fb91c933fe53d9db0c8b985 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 18:30:52 +0100 Subject: tweak colors --- data/vertice.png | Bin 4505 -> 4488 bytes egraph.edc | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/data/vertice.png b/data/vertice.png index 7cf4dcd..54c556b 100644 Binary files a/data/vertice.png and b/data/vertice.png differ diff --git a/egraph.edc b/egraph.edc index 0a62e28..5b40c01 100644 --- a/egraph.edc +++ b/egraph.edc @@ -23,7 +23,7 @@ collections { description { state: "group" 1.0; inherit: "default" 0.0; - color: 255 255 255 50; + color: 120 120 40 150; } } } @@ -61,7 +61,7 @@ collections { description { state: "group" 1.0; inherit: "default" 0.0; - color: 255 255 255 50; + color: 120 120 40 150; } } } -- cgit v1.2.3-59-g8ed1b From 9184086bdaa4b7f1b172add31e699d3aa66d1863 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 18:31:31 +0100 Subject: remove useless part --- egraph.edc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/egraph.edc b/egraph.edc index 5b40c01..a92e32b 100644 --- a/egraph.edc +++ b/egraph.edc @@ -96,12 +96,6 @@ collections { rel1.relative: 0.0 0.0; rel2.relative: 1.0 1.0; } - description { - state: "down-state" 1.0; - inherit: "default" 0.0; - rel1.relative: 0.0 1.0; - rel2.relative: 0.0 0.0; - } } } } -- cgit v1.2.3-59-g8ed1b From 69efa310c22c13d2a784d10e7eb13889003af559 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 20:23:12 +0100 Subject: increase vertice size a bit --- egraph.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/egraph.c b/egraph.c index b56a831..8abe2d5 100644 --- a/egraph.c +++ b/egraph.c @@ -6,8 +6,8 @@ #define DEBUG 0 -#define VERTICE_OBJ_W 15 -#define VERTICE_OBJ_H 15 +#define VERTICE_OBJ_W 18 +#define VERTICE_OBJ_H 18 #define VERTICE_TEXT_W 20 // XXX dynamicaly get the max on each new name #define VERTICE_TEXT_H 10 #define VERTICE_W (VERTICE_OBJ_W + VERTICE_TEXT_W) -- cgit v1.2.3-59-g8ed1b From 0ccdf51ea1fb6789d4fafea6be878315167dcf33 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 20:23:48 +0100 Subject: vertice and edges now have a type ("normal" and "group") and a status ("active" and "inactive") --- Egraph.h | 1 + egraph.c | 93 +++++++++++++++++++++++++++++++++++------------- egraph.edc | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 176 insertions(+), 36 deletions(-) diff --git a/Egraph.h b/Egraph.h index ac70bcc..5a6023a 100644 --- a/Egraph.h +++ b/Egraph.h @@ -58,6 +58,7 @@ struct Egraph_Vertice { u_int32_t id; char *name; char *type; + int status; Evas_Object *o; int o_usetheme; Evas_Object *o_text; diff --git a/egraph.c b/egraph.c index 8abe2d5..569dd2f 100644 --- a/egraph.c +++ b/egraph.c @@ -13,20 +13,23 @@ #define VERTICE_W (VERTICE_OBJ_W + VERTICE_TEXT_W) #define VERTICE_H (VERTICE_OBJ_H + VERTICE_TEXT_H) +#define TYPE_MAXLEN 30 + static void _smart_add(Evas_Object *obj); static void _smart_del(Evas_Object *obj); static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y); static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h); static void _edge_v2_add(Egraph *eg, Egraph_Edge *e); static void _edge_add(Egraph *eg, Egraph_Edge *e); -static void _edge_type_update(Egraph *eg, Egraph_Edge *e); +static void _edge_signal(Egraph *eg, Egraph_Edge *e, const char *signal); static void _edge_v2_del(Egraph *eg, Egraph_Edge *e); static void _edge_del(Egraph *eg, Egraph_Edge *e); static void _vertice_v2_add(Egraph *eg, Egraph_Vertice *v); static void _vertice_add(Egraph *eg, Egraph_Vertice *v); static void _vertice_v2_del(Egraph *eg, Egraph_Vertice *v); -static void _vertice_type_update(Egraph *eg, Egraph_Vertice *v); static void _vertice_del(Egraph *eg, Egraph_Vertice *v); +static void _vertice_update_status(Egraph *eg, Egraph_Vertice *v); +static void _vertice_signal(Egraph *eg, Egraph_Vertice *v, const char *signal); static void _v2_update(Egraph *eg); static void _v3_update(Egraph *eg); static void _coords2_copy(Egraph *eg); @@ -45,7 +48,8 @@ static void _reposition(Egraph *eg, int no_animation); static void _matrix_minmax_2v(const igraph_matrix_t *m, int row_count, float *c1min, float *c1max, float *c2min, float *c2max); -static Evas_Object *_edje_obj_new(Egraph *eg, char *group); +static Evas_Object *_edje_obj_new(Egraph *eg, const char *group); +static Evas_Object *_edje_obj_set(Egraph *eg, Evas_Object *o, const char *group); static const Evas_Smart_Cb_Description _smart_callbacks[] = {{NULL, NULL}}; #define EGRAPH_DATA_GET(o, ptr) \ @@ -325,6 +329,8 @@ egraph_edge_add(Evas_Object *obj, Egraph_Vertice *a, Egraph_Vertice *b, if (DEBUG) printf("egraph_edge_add %d %d\n", e->a->id, e->b->id); + egraph_edge_type_set(obj, e, "edge_normal"); + _layouting_schedule(eg); return e; } @@ -359,7 +365,7 @@ _edge_add(Egraph *eg, Egraph_Edge *e) igraph_add_edge(&eg->graph, a_pos, b_pos); if (eg->theme_edges) { - eobj = _edje_obj_new(eg, "edge"); + eobj = _edje_obj_new(eg, e->type); if (eobj) { e->o_usetheme = 1; evas_object_resize(eobj, VERTICE_OBJ_W, VERTICE_OBJ_H); // XXX rm @@ -372,10 +378,12 @@ _edge_add(Egraph *eg, Egraph_Edge *e) evas_object_smart_member_add(eobj, eg->obj); evas_object_stack_below(eobj, eg->split_vertice_edge); e->o = eobj; - _edge_type_update(eg, e); + _edge_signal(eg, e, "become_active"); e->a->edges = eina_list_append(e->a->edges, e); e->b->edges = eina_list_append(e->b->edges, e); + _vertice_update_status(eg, e->a); + _vertice_update_status(eg, e->b); } void @@ -385,18 +393,18 @@ egraph_edge_type_set(Evas_Object *obj, Egraph_Edge *e, const char *type) if (e->type) free(e->type); - e->type = strndup(type, 30); - _edge_type_update(eg, e); + + e->type = strndup(type, TYPE_MAXLEN); + if (eg->theme_edges && e->o) { + _edje_obj_set(eg, e->o, type); + } } static void -_edge_type_update(Egraph *eg, Egraph_Edge *e) +_edge_signal(Egraph *eg, Egraph_Edge *e, const char *signal) { - if (!e->type) - return; - if (eg->theme_edges && e->o); - edje_object_signal_emit(e->o, e->type, ""); + edje_object_signal_emit(e->o, signal, ""); } void @@ -451,6 +459,9 @@ _edge_del(Egraph *eg, Egraph_Edge *e) e->a->edges = eina_list_remove(e->a->edges, e); e->b->edges = eina_list_remove(e->b->edges, e); + _vertice_update_status(eg, e->a); + _vertice_update_status(eg, e->b); + evas_object_del(e->o); } eg->edges = eina_list_remove(eg->edges, e); @@ -496,6 +507,7 @@ egraph_vertice_add(Evas_Object *obj, const char *name, void *data) if (name) v->name = strndup(name, EGRAPH_VERTICE_NAME_MAXLEN); + egraph_vertice_type_set(obj, v, "vertice_normal"); v->data = data; @@ -528,7 +540,7 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) eg->graph_vcount++; if (eg->theme_vertices) { - vobj = _edje_obj_new(eg, "vertice"); + vobj = _edje_obj_new(eg, v->type); if (vobj) v->o_usetheme = 1; } @@ -541,7 +553,6 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) evas_object_resize(vobj, VERTICE_OBJ_W, VERTICE_OBJ_H); evas_object_event_callback_add(vobj, EVAS_CALLBACK_MOVE, _cb_vertice_move, v); v->o = vobj; - _vertice_type_update(eg, v); text = evas_object_text_add(eg->evas); evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); @@ -638,18 +649,46 @@ egraph_vertice_type_set(Evas_Object *obj, Egraph_Vertice *v, const char *type) if (v->type) free(v->type); - v->type = strndup(type, 30); - _vertice_type_update(eg, v); + + v->type = strndup(type, TYPE_MAXLEN); + if (eg->theme_vertices && v->o) { + _edje_obj_set(eg, v->o, type); + } } static void -_vertice_type_update(Egraph *eg, Egraph_Vertice *v) +_vertice_update_status(Egraph *eg, Egraph_Vertice *v) { - if (!v->type) - return; + Eina_List *l; + Egraph_Edge *e; + int status = 0; - if (eg->theme_edges && v->o); - edje_object_signal_emit(v->o, v->type, ""); + if (v->group_vertices && (eina_list_count(v->edges) >= 1)) { + status = 1; /* we are a group with childs */ + } else { + EINA_LIST_FOREACH(v->edges, l, e) { + if ((v == e->a && !e->b->group_vertices) || + (v == e->b && !e->a->group_vertices)) { + status = 1; /* we are connected to at least on other non group node */ + break; + } + } + } + + if (status != v->status) { + if (status) + _vertice_signal(eg, v, "become_active"); + else + _vertice_signal(eg, v, "become_inactive"); + v->status = status; + } +} + +static void +_vertice_signal(Egraph *eg, Egraph_Vertice *v, const char *signal) +{ + if (eg->theme_vertices && v->o); + edje_object_signal_emit(v->o, signal, ""); } void @@ -1200,11 +1239,17 @@ _matrix_minmax_2v(const igraph_matrix_t *m, int row_count, } static Evas_Object * -_edje_obj_new(Egraph *eg, char *group) +_edje_obj_new(Egraph *eg, const char *group) { Evas_Object *obj; obj = edje_object_add(eg->evas); + return _edje_obj_set(eg, obj, group); +} + +static Evas_Object * +_edje_obj_set(Egraph *eg, Evas_Object *obj, const char *group) +{ if (!obj || !edje_object_file_set(obj, eg->theme_path, group)) { int err = edje_object_load_error_get(obj); const char *errmsg = edje_load_error_str(err); @@ -1221,7 +1266,7 @@ egraph_group_add(Evas_Object *obj, const char *name, void *data) Egraph_Vertice *g; g = egraph_vertice_add(obj, name, data); - egraph_vertice_type_set(obj, g, "become_group"); + egraph_vertice_type_set(obj, g, "vertice_group"); return g; } @@ -1233,7 +1278,7 @@ egraph_group_vertice_attach(Evas_Object *obj, group->group_vertices = eina_list_append(group->group_vertices, v); e = egraph_edge_add(obj, group, v, NULL); - egraph_edge_type_set(obj, e, "become_group"); + egraph_edge_type_set(obj, e, "edge_group"); return 1; } diff --git a/egraph.edc b/egraph.edc index a92e32b..26d5457 100644 --- a/egraph.edc +++ b/egraph.edc @@ -1,6 +1,6 @@ collections { group { - name: "vertice"; + name: "vertice_normal"; max: 700 700; min: 700 700; images { @@ -19,9 +19,56 @@ collections { } rel1.relative: 0.0 0.0; rel2.relative: 1.0 1.0; + color: 255 255 255 100; } description { - state: "group" 1.0; + state: "active" 1.0; + inherit: "default" 0.0; + color: 255 255 255 255; + } + } + } + programs { + program { + name: "state_active"; + signal: "become_active"; + action: STATE_SET "active" 0.0; + target: "image"; + transition: DECELERATE 0.5; + } + program { + name: "state_inactive"; + signal: "become_inactive"; + action: STATE_SET "default" 0.0; + target: "image"; + transition: DECELERATE 0.5; + } + } + } + group { + name: "vertice_group"; + max: 700 700; + min: 700 700; + images { + image: "data/vertice.png" COMP; + } + parts { + part { + name: "image"; + type: IMAGE; + description { + state: "default" 0.0; + max: 15 15; + min: 15 15; + image{ + normal: "data/vertice.png"; + } + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + color: 120 120 40 50; + } + description { + state: "active" 1.0; inherit: "default" 0.0; color: 120 120 40 150; } @@ -29,16 +76,62 @@ collections { } programs { program { - name: "state_group"; - signal: "become_group"; - action: STATE_SET "group" 0.0; + name: "state_active"; + signal: "become_active"; + action: STATE_SET "active" 0.0; + target: "image"; + transition: DECELERATE 0.5; + } + program { + name: "state_inactive"; + signal: "become_inactive"; + action: STATE_SET "default" 0.0; + target: "image"; + transition: DECELERATE 0.5; + } + } + } + group { + name: "edge_normal"; + max: 700 700; + min: 700 700; + images { + image: "data/edge.png" COMP; + } + parts { + part { + name: "image"; + type: IMAGE; + description { + state: "default" 0.0; + max: 50 10; + min: 50 10; + image{ + normal: "data/edge.png"; + } + rel1.relative: 0.0 0.0; + rel2.relative: 1.0 1.0; + color: 255 255 255 50; + } + description { + state: "active" 1.0; + inherit: "default" 0.0; + color: 255 255 255 255; + } + } + } + programs { + program { + name: "state_active"; + signal: "become_active"; + action: STATE_SET "active" 0.0; target: "image"; - transition: DECELERATE 0.5; + transition: DECELERATE 0.5; } } } group { - name: "edge"; + name: "edge_group"; max: 700 700; min: 700 700; images { @@ -57,9 +150,10 @@ collections { } rel1.relative: 0.0 0.0; rel2.relative: 1.0 1.0; + color: 120 120 40 50; } description { - state: "group" 1.0; + state: "active" 1.0; inherit: "default" 0.0; color: 120 120 40 150; } @@ -67,11 +161,11 @@ collections { } programs { program { - name: "state_group"; - signal: "become_group"; - action: STATE_SET "group" 0.0; + name: "state_active"; + signal: "become_active"; + action: STATE_SET "active" 0.0; target: "image"; - transition: DECELERATE 0.5; + transition: DECELERATE 0.5; } } } -- cgit v1.2.3-59-g8ed1b From 825078beee2f061faeb87c59f2aecb5bf9e43fc0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 20:25:47 +0100 Subject: use 1 bit for boolean integer. --- Egraph.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Egraph.h b/Egraph.h index 5a6023a..3395c54 100644 --- a/Egraph.h +++ b/Egraph.h @@ -58,9 +58,9 @@ struct Egraph_Vertice { u_int32_t id; char *name; char *type; - int status; + u_int status : 1; Evas_Object *o; - int o_usetheme; + u_int o_usetheme : 1; Evas_Object *o_text; Eina_List *edges; Eina_List *blobs_incoming; @@ -78,7 +78,7 @@ struct Egraph_Edge { Egraph_Vertice *b; char *type; Evas_Object *o; - int o_usetheme; + u_int o_usetheme : 1; void *data; u_int new : 1; u_int v2_new : 1; -- cgit v1.2.3-59-g8ed1b From 904f930c762db69a1313716b978cffc9a41df983 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 21:10:30 +0100 Subject: specify empty source in programs --- egraph.edc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/egraph.edc b/egraph.edc index 26d5457..3159b96 100644 --- a/egraph.edc +++ b/egraph.edc @@ -32,6 +32,7 @@ collections { program { name: "state_active"; signal: "become_active"; + source: ""; action: STATE_SET "active" 0.0; target: "image"; transition: DECELERATE 0.5; @@ -39,6 +40,7 @@ collections { program { name: "state_inactive"; signal: "become_inactive"; + source: ""; action: STATE_SET "default" 0.0; target: "image"; transition: DECELERATE 0.5; -- cgit v1.2.3-59-g8ed1b From 9e7c853c49824298f06fa53bddcccae09f5152d9 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 21:11:37 +0100 Subject: fix inactive transition for vertices by having a group boolean set for vertices that are vertices groups --- Egraph.h | 1 + egraph.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Egraph.h b/Egraph.h index 3395c54..4fbc8c2 100644 --- a/Egraph.h +++ b/Egraph.h @@ -65,6 +65,7 @@ struct Egraph_Vertice { Eina_List *edges; Eina_List *blobs_incoming; void *data; + u_int is_group : 1; Eina_List *group_vertices; /* used if the vertice is a group */ u_int new : 1; u_int v2_new : 1; diff --git a/egraph.c b/egraph.c index 569dd2f..f30e273 100644 --- a/egraph.c +++ b/egraph.c @@ -663,12 +663,12 @@ _vertice_update_status(Egraph *eg, Egraph_Vertice *v) Egraph_Edge *e; int status = 0; - if (v->group_vertices && (eina_list_count(v->edges) >= 1)) { + if (v->is_group && (eina_list_count(v->edges) >= 1)) { status = 1; /* we are a group with childs */ } else { EINA_LIST_FOREACH(v->edges, l, e) { - if ((v == e->a && !e->b->group_vertices) || - (v == e->b && !e->a->group_vertices)) { + if ((v == e->a && !e->b->is_group) || + (v == e->b && !e->a->is_group)) { status = 1; /* we are connected to at least on other non group node */ break; } @@ -1266,6 +1266,7 @@ egraph_group_add(Evas_Object *obj, const char *name, void *data) Egraph_Vertice *g; g = egraph_vertice_add(obj, name, data); + g->is_group = 1; egraph_vertice_type_set(obj, g, "vertice_group"); return g; } -- cgit v1.2.3-59-g8ed1b From 1edb615dd954e0daba2c60168cd8bb573a739753 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 21:15:22 +0100 Subject: better indentation of struct members, no functionnal change --- Egraph.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Egraph.h b/Egraph.h index 4fbc8c2..4426f98 100644 --- a/Egraph.h +++ b/Egraph.h @@ -55,18 +55,18 @@ struct Egraph { }; struct Egraph_Vertice { - u_int32_t id; - char *name; - char *type; - u_int status : 1; + u_int32_t id; + char *name; + char *type; + u_int status : 1; Evas_Object *o; u_int o_usetheme : 1; Evas_Object *o_text; - Eina_List *edges; - Eina_List *blobs_incoming; - void *data; - u_int is_group : 1; - Eina_List *group_vertices; /* used if the vertice is a group */ + Eina_List *edges; + Eina_List *blobs_incoming; + void *data; + u_int is_group : 1; + Eina_List *group_vertices; /* used if the vertice is a group */ u_int new : 1; u_int v2_new : 1; u_int v2_del : 1; @@ -77,10 +77,10 @@ struct Egraph_Vertice { struct Egraph_Edge { Egraph_Vertice *a; Egraph_Vertice *b; - char *type; - Evas_Object *o; - u_int o_usetheme : 1; - void *data; + char *type; + Evas_Object *o; + u_int o_usetheme : 1; + void *data; u_int new : 1; u_int v2_new : 1; u_int v2_del : 1; -- cgit v1.2.3-59-g8ed1b From 58ca0218b73bc5291f304cc6e254f7999b52ea5d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 22:26:45 +0100 Subject: add some Thanks ! --- README | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README b/README index f82901b..a209b6d 100644 --- a/README +++ b/README @@ -35,6 +35,8 @@ Thanks Thanks to ntamas (http://sixdegrees.hu/) for her advices on igraph. Thanks to raster for tech advices on evas / elementary. +Thanks to cedric for tech advices on evas / edge. +Thanks to vtorri for tech advices on evas / edge. Thanks to ludivina for graphical advices. History -- cgit v1.2.3-59-g8ed1b From f43b67f8632b0bac478ff299dd87643778e73cae Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 22:34:46 +0100 Subject: drop support for having non themed vertices, and update demoapp in consequence. needed for simplicity in future vertice theming refactor. --- Egraph.h | 7 ------- egraph.c | 36 +++++++++++++----------------------- examples/demoapp.c | 16 ---------------- 3 files changed, 13 insertions(+), 46 deletions(-) diff --git a/Egraph.h b/Egraph.h index 4426f98..d942b15 100644 --- a/Egraph.h +++ b/Egraph.h @@ -30,7 +30,6 @@ struct Egraph { int use_animations; int do_improvements; char *theme_path; - int theme_vertices; int theme_edges; Egraph_Layout layout; struct { @@ -60,7 +59,6 @@ struct Egraph_Vertice { char *type; u_int status : 1; Evas_Object *o; - u_int o_usetheme : 1; Evas_Object *o_text; Eina_List *edges; Eina_List *blobs_incoming; @@ -103,11 +101,6 @@ void egraph_clear(Evas_Object *obj); */ void egraph_theme_file_set(Evas_Object *obj, char *path); -/** - * Sets if egraph should theme the vertices - */ -void egraph_theme_vertices_set(Evas_Object *obj, int set); - /** * Sets if egraph should theme the edges */ diff --git a/egraph.c b/egraph.c index f30e273..65c4109 100644 --- a/egraph.c +++ b/egraph.c @@ -139,7 +139,6 @@ egraph_new(Evas *evas, int directed) eg->use_animations = 1; eg->do_improvements = 1; egraph_theme_file_set(obj, NULL); - eg->theme_vertices = 1; eg->theme_edges = 1; eg->layout = EGRAPH_LAYOUT_DEFAULT; @@ -203,14 +202,6 @@ egraph_theme_file_set(Evas_Object *obj, char *path) eg->theme_path = strndup(path, 256); } -void -egraph_theme_vertices_set(Evas_Object *obj, int set) -{ - EGRAPH_DATA_GET(obj, eg); - - eg->theme_vertices = set; -} - void egraph_theme_edges_set(Evas_Object *obj, int set) { @@ -535,19 +526,15 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) v->new = 1; v->v2_new = 0; - igraph_add_vertices(&eg->graph, 1, 0); - SETVAN(&eg->graph, "id", eg->graph_vcount, v->id); - eg->graph_vcount++; - - if (eg->theme_vertices) { - vobj = _edje_obj_new(eg, v->type); - if (vobj) - v->o_usetheme = 1; - } + vobj = _edje_obj_new(eg, v->type); if (!vobj) { - vobj = evas_object_rectangle_add(eg->evas); - evas_object_color_set(vobj, 0, 0, 255, 255); + printf("egraph: could not load theme for vertice !"); + v->v2_new = 1; + v->new = 0; + _vertice_v2_del(eg, v); + return; } + evas_object_smart_member_add(vobj, eg->obj); evas_object_stack_above(vobj, eg->split_vertice_edge); evas_object_resize(vobj, VERTICE_OBJ_W, VERTICE_OBJ_H); @@ -562,6 +549,10 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) evas_object_stack_above(text, eg->split_vertice_edge); v->o_text = text; + igraph_add_vertices(&eg->graph, 1, 0); + SETVAN(&eg->graph, "id", eg->graph_vcount, v->id); + eg->graph_vcount++; + if (v->name) egraph_vertice_rename(eg->obj, v, v->name); } @@ -651,9 +642,8 @@ egraph_vertice_type_set(Evas_Object *obj, Egraph_Vertice *v, const char *type) free(v->type); v->type = strndup(type, TYPE_MAXLEN); - if (eg->theme_vertices && v->o) { + if (v->o) _edje_obj_set(eg, v->o, type); - } } static void @@ -687,7 +677,7 @@ _vertice_update_status(Egraph *eg, Egraph_Vertice *v) static void _vertice_signal(Egraph *eg, Egraph_Vertice *v, const char *signal) { - if (eg->theme_vertices && v->o); + if (v->o) edje_object_signal_emit(v->o, signal, ""); } diff --git a/examples/demoapp.c b/examples/demoapp.c index af3211f..4e64363 100644 --- a/examples/demoapp.c +++ b/examples/demoapp.c @@ -172,15 +172,6 @@ _cb_do_improvements(void *data, Evas_Object *obj, void *event_info) egraph_do_improvements_set(_egraph, elm_check_state_get(obj)); } -static void -_cb_use_theme_v(void *data, Evas_Object *obj, void *event_info) -{ - if (!_egraph) - return; - - egraph_theme_vertices_set(_egraph, elm_check_state_get(obj)); -} - static void _cb_use_theme_e(void *data, Evas_Object *obj, void *event_info) { @@ -326,13 +317,6 @@ elm_main(int argc, char **argv) tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); elm_object_item_part_content_set(tb_it, "object", ck); ck = elm_check_add(win); - elm_object_text_set(ck, "Use theme for vertices"); - elm_check_state_set(ck, EINA_TRUE); - evas_object_show(ck); - evas_object_smart_callback_add(ck, "changed", _cb_use_theme_v, NULL); - tb_it = elm_toolbar_item_append(tb, NULL, NULL, NULL, NULL); - elm_object_item_part_content_set(tb_it, "object", ck); - ck = elm_check_add(win); elm_object_text_set(ck, "Use theme for edges"); elm_check_state_set(ck, EINA_TRUE); evas_object_show(ck); -- cgit v1.2.3-59-g8ed1b From 220be7b56f68342767a94b7f7651385b6c0770d0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 23:04:48 +0100 Subject: update regarding current dev --- doc/TODO.txt | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/doc/TODO.txt b/doc/TODO.txt index 2525eef..0cb6244 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -1,27 +1,31 @@ -TODO -==== +CURRENT +======= -* zoom +vertice / vertice_text visibility will be broken +need to implement it in the edje object and send signals + +edje_object_part_text_set() is done in egraph_display_names_set() +AND egraph_vertice_rename() ... spank * BUG: show nodes labels does not show old nodes labels reproduce: do not show labels, add edges, show label, add edges -* BUG: sometimes when you add nodes during layouting, the graph is broken -a new edge attaches to the wrong new vertice -it seems to be always the same node numbers that gets this wrong edge +* BUG: layer stacking is wrong, edges end up on top of nodes, despite +eg->split_vertice_edge * BUG: vertices / vertices text fight for being on top. use evas layers ? add 500 edges to reproduce, and watch the nodes -* BUG: layer stacking is wrong, edges end up on top of nodes, despite -eg->split_vertice_edge +TODO +==== + +* BUG: sometimes when you add nodes during layouting, the graph is broken +a new edge attaches to the wrong new vertice +it seems to be always the same node numbers that gets this wrong edge * BUG: EGRAPH_LAYOUT_FRUCHTERMANREINGOLD is broken when adding many edges -* speed: evas_object_rectangles -04:40 <@raster> they add clipoouts -04:41 <@raster> make them just a bit translucent -04:41 <@raster> and it'll be faster +* zoom * find a better storage type for vertices quick access O(1) -> table @@ -63,3 +67,12 @@ renders to OpenGL directly used by : http://code.google.com/p/logstalgia/ https://github.com/acaudwell/Gource (http://code.google.com/p/gource/) + +OLD +=== + +* speed: evas_object_rectangles +04:40 <@raster> they add clipoouts +04:41 <@raster> make them just a bit translucent +04:41 <@raster> and it'll be faster + -- cgit v1.2.3-59-g8ed1b From 2aed0c7d626e4dcee8a65bbe65d1e7730574ac5f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Thu, 13 Dec 2012 23:16:11 +0100 Subject: wording --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index a209b6d..7f3b14f 100644 --- a/README +++ b/README @@ -43,4 +43,4 @@ History ======= Egraph was developped for the Glouglou Network Map (gg_map), a tool for -live network visualisation based on the Glouglou framework. +live computer network visualisation based on the Glouglou framework. -- cgit v1.2.3-59-g8ed1b From e362b7191d867e799755ae50260c5768ba3b4373 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 14 Dec 2012 01:48:37 +0100 Subject: updat --- doc/TODO.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/TODO.txt b/doc/TODO.txt index 0cb6244..e23ce65 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -4,9 +4,6 @@ CURRENT vertice / vertice_text visibility will be broken need to implement it in the edje object and send signals -edje_object_part_text_set() is done in egraph_display_names_set() -AND egraph_vertice_rename() ... spank - * BUG: show nodes labels does not show old nodes labels reproduce: do not show labels, add edges, show label, add edges @@ -19,6 +16,9 @@ add 500 edges to reproduce, and watch the nodes TODO ==== +* missing function declaration for static _color_int_to_rgb() +* reorder static funcs + * BUG: sometimes when you add nodes during layouting, the graph is broken a new edge attaches to the wrong new vertice it seems to be always the same node numbers that gets this wrong edge -- cgit v1.2.3-59-g8ed1b From ff87a6a44d8184e1d18ed67cdf27c458e0adacb3 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 14 Dec 2012 01:48:54 +0100 Subject: new vertice * text + image in one edje object * respect active and inactive status * size of image and text determined by the theme --- Egraph.h | 3 ++- egraph.c | 78 ++++++++++++++++++++++++++------------------------------------ egraph.edc | 60 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 91 insertions(+), 50 deletions(-) diff --git a/Egraph.h b/Egraph.h index d942b15..7f4d6c5 100644 --- a/Egraph.h +++ b/Egraph.h @@ -42,6 +42,8 @@ struct Egraph { Eina_Hash *vertices; int vertices_count; u_int32_t vertices_freeids[EGRAPH_VERTICES_MAX]; + int vertice_max_w; + int vertice_max_h; Eina_List *edges; igraph_t graph; int graph_vcount; @@ -59,7 +61,6 @@ struct Egraph_Vertice { char *type; u_int status : 1; Evas_Object *o; - Evas_Object *o_text; Eina_List *edges; Eina_List *blobs_incoming; void *data; diff --git a/egraph.c b/egraph.c index 65c4109..990c9ce 100644 --- a/egraph.c +++ b/egraph.c @@ -6,13 +6,6 @@ #define DEBUG 0 -#define VERTICE_OBJ_W 18 -#define VERTICE_OBJ_H 18 -#define VERTICE_TEXT_W 20 // XXX dynamicaly get the max on each new name -#define VERTICE_TEXT_H 10 -#define VERTICE_W (VERTICE_OBJ_W + VERTICE_TEXT_W) -#define VERTICE_H (VERTICE_OBJ_H + VERTICE_TEXT_H) - #define TYPE_MAXLEN 30 static void _smart_add(Evas_Object *obj); @@ -30,6 +23,7 @@ static void _vertice_v2_del(Egraph *eg, Egraph_Vertice *v); static void _vertice_del(Egraph *eg, Egraph_Vertice *v); static void _vertice_update_status(Egraph *eg, Egraph_Vertice *v); static void _vertice_signal(Egraph *eg, Egraph_Vertice *v, const char *signal); +static void _vertice_geometry_update(Egraph *eg, Egraph_Vertice *v); static void _v2_update(Egraph *eg); static void _v3_update(Egraph *eg); static void _coords2_copy(Egraph *eg); @@ -158,6 +152,8 @@ egraph_new(Evas *evas, int directed) eg->graph_wmax = 200; eg->graph_hmin = 0; eg->graph_hmax = 200; + eg->vertice_max_w = 0; + eg->vertice_max_h = 0; return obj; @@ -258,12 +254,7 @@ egraph_display_names_set(Evas_Object *obj, int set) while (eina_iterator_next(it, &data)) { Eina_Hash_Tuple *t = data; v = t->data; - if (v->o_text) { - if (set == 0) - evas_object_hide(v->o_text); - else - evas_object_show(v->o_text); - } + egraph_vertice_rename(obj, v, set ? v->name : NULL); } } @@ -359,7 +350,7 @@ _edge_add(Egraph *eg, Egraph_Edge *e) eobj = _edje_obj_new(eg, e->type); if (eobj) { e->o_usetheme = 1; - evas_object_resize(eobj, VERTICE_OBJ_W, VERTICE_OBJ_H); // XXX rm + evas_object_resize(eobj, eg->vertice_max_w, eg->vertice_max_h); // XXX rm } } if (!eobj) { @@ -521,7 +512,6 @@ static void _vertice_add(Egraph *eg, Egraph_Vertice *v) { Evas_Object *vobj = NULL; - Evas_Object *text; v->new = 1; v->v2_new = 0; @@ -534,20 +524,11 @@ _vertice_add(Egraph *eg, Egraph_Vertice *v) _vertice_v2_del(eg, v); return; } - evas_object_smart_member_add(vobj, eg->obj); evas_object_stack_above(vobj, eg->split_vertice_edge); - evas_object_resize(vobj, VERTICE_OBJ_W, VERTICE_OBJ_H); evas_object_event_callback_add(vobj, EVAS_CALLBACK_MOVE, _cb_vertice_move, v); v->o = vobj; - - text = evas_object_text_add(eg->evas); - evas_object_text_style_set(text, EVAS_TEXT_STYLE_PLAIN); - evas_object_color_set(text, 200, 255, 0, 255); - evas_object_text_font_set(text, "Vera-Bold", VERTICE_TEXT_H); - evas_object_smart_member_add(text, eg->obj); - evas_object_stack_above(text, eg->split_vertice_edge); - v->o_text = text; + _vertice_geometry_update(eg, v); igraph_add_vertices(&eg->graph, 1, 0); SETVAN(&eg->graph, "id", eg->graph_vcount, v->id); @@ -622,8 +603,6 @@ _vertice_del(Egraph *eg, Egraph_Vertice *v) eina_list_free(v->blobs_incoming); evas_object_del(v->o); - if (v->o_text) - evas_object_del(v->o_text); } eina_hash_del(eg->vertices, &v->id, NULL); @@ -695,13 +674,32 @@ egraph_vertice_rename(Evas_Object *obj, Egraph_Vertice *v, const char *name) free(v->name); v->name = strndup(name, EGRAPH_VERTICE_NAME_MAXLEN); } - evas_object_text_text_set(v->o_text, name); - evas_object_show(v->o_text); - } else { - evas_object_hide(v->o_text); + } + if (v->o) { + if (v->name) + edje_object_part_text_set(v->o, "label", v->name); + else + edje_object_part_text_set(v->o, "label", ""); + _vertice_geometry_update(eg, v); } } +static void +_vertice_geometry_update(Egraph *eg, Egraph_Vertice *v) +{ + int w, h; + + edje_object_size_min_calc(v->o, &w, &h); + printf("_vertice_geometry_update: %d %d\n", w, h); + evas_object_resize(v->o, w, h); + if (w > eg->vertice_max_w) + eg->vertice_max_w = w; + if (h > eg->vertice_max_h) + eg->vertice_max_h = h; + printf("_vertice_geometry_update: end %d %d\n", + eg->vertice_max_w, eg->vertice_max_h); +} + void _color_int_to_rgb(u_int32_t color, int *r, int *g , int *b) { @@ -1059,7 +1057,7 @@ _igraph_query_vid(igraph_t *g, int g_len, int id) return -1; } -/* Apply vertice move to it's name text object and it's edges */ +/* Apply vertice move to it's edges */ static void _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) { @@ -1076,13 +1074,6 @@ _cb_vertice_move(void *data, Evas *evas, Evas_Object *obj, void *event_info) v = data; evas_object_geometry_get(v->o, &x, &y, &w, &h); - if (eg->display_names) { - if (eg->display_vertices) - evas_object_move(v->o_text, x+3, y+8); - else - evas_object_move(v->o_text, x, y); - } - EINA_LIST_FOREACH(v->edges, l, e) { if (e->new) { if (eg->display_edges) @@ -1160,11 +1151,11 @@ _reposition(Egraph *eg, int no_animation) if (gw_max == gw_min) factor_w = 1; else - factor_w = (obj_w - VERTICE_W) / (gw_max - gw_min); + factor_w = (obj_w - eg->vertice_max_w) / (gw_max - gw_min); if (gh_max == gh_min) factor_h = 1; else - factor_h = (obj_h - VERTICE_H) / (gh_max - gh_min); + factor_h = (obj_h - eg->vertice_max_h) / (gh_max - gh_min); if (DEBUG) printf("factor_w %6.3f factor_h %6.3f\n", factor_w, factor_h); @@ -1194,10 +1185,7 @@ _reposition(Egraph *eg, int no_animation) _blob_send(blob, v, x, y); */ if (v->new) { - if (eg->display_vertices) - evas_object_show(v->o); - if (eg->display_names) - evas_object_show(v->o_text); + evas_object_show(v->o); v->new = 0; } } diff --git a/egraph.edc b/egraph.edc index 3159b96..399442a 100644 --- a/egraph.edc +++ b/egraph.edc @@ -27,6 +27,31 @@ collections { color: 255 255 255 255; } } + part { + name: "label"; + type: TEXT; + description { + state: "default" 0.0; + max: 50 8; + fixed: 1 1; + color: 200 255 0 50; /* yellow low */ + text { + font: "vera"; + size: 10; + min: 1 1; + } + rel1.to: "image"; + rel1.relative: 0.5 1.0; + rel2.to: "image"; + rel2.relative: 0.5 1.0; + rel2.offset: 0 8; + } + description { + state: "active" 1.0; + inherit: "default" 0.0; + color: 200 255 0 255; /* yellow visible */ + } + } } programs { program { @@ -35,6 +60,7 @@ collections { source: ""; action: STATE_SET "active" 0.0; target: "image"; + target: "label"; transition: DECELERATE 0.5; } program { @@ -43,6 +69,7 @@ collections { source: ""; action: STATE_SET "default" 0.0; target: "image"; + target: "label"; transition: DECELERATE 0.5; } } @@ -67,12 +94,37 @@ collections { } rel1.relative: 0.0 0.0; rel2.relative: 1.0 1.0; - color: 120 120 40 50; + color: 160 120 40 70; + } + description { + state: "active" 1.0; + inherit: "default" 0.0; + color: 160 120 40 170; + } + } + part { + name: "label"; + type: TEXT; + description { + state: "default" 0.0; + max: 50 8; + fixed: 1 1; + color: 160 120 40 70; /* yellow low */ + text { + font: "vera"; + size: 10; + min: 1 1; + } + rel1.to: "image"; + rel1.relative: 0.5 1.0; + rel2.to: "image"; + rel2.relative: 0.5 1.0; + rel2.offset: 0 8; } description { state: "active" 1.0; inherit: "default" 0.0; - color: 120 120 40 150; + color: 160 120 40 170; /* yellow visible */ } } } @@ -152,12 +204,12 @@ collections { } rel1.relative: 0.0 0.0; rel2.relative: 1.0 1.0; - color: 120 120 40 50; + color: 255 120 40 70; } description { state: "active" 1.0; inherit: "default" 0.0; - color: 120 120 40 150; + color: 255 120 40 170; } } } -- cgit v1.2.3-59-g8ed1b From fbca13e9eaa701ab911918c6a03680e4cc5d338d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 14 Dec 2012 06:53:58 +0100 Subject: TODO++ on blobs --- doc/TODO.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/doc/TODO.txt b/doc/TODO.txt index e23ce65..6353ec8 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -27,6 +27,31 @@ it seems to be always the same node numbers that gets this wrong edge * zoom +* blobs +05:17 < glouglou> cedric: t'as vu dans ma demo les packets qui vont d'une node a l'autre quand les nodes bougent et ben les paquets arrivent a l'ancien endroit +05:17 < glouglou> j'ai regarde un peu dans efx mais j'ai pas trouve de bon moyen +05:18 < glouglou> il faudrait que les paquets ne puissent pas sortir de l'edge (le trait) entre les 2 nodes +05:18 < glouglou> si tu as une idee ... +05:22 -!- Munto [~frugal@2a01:e35:139d:91e0:221:85ff:fee1:5c3c] has quit [Read error: Connection reset by peer] +05:33 -!- sharinganex [~sharingan@233.208.85.79.rev.sfr.net] has joined #e.fr +06:22 <@cedric> glouglou: oui, swallow un smart objet +06:22 <@cedric> qui n'a qu'une seule tache faire bouger des paquets de haut en bas et de bas en haut +06:22 <@cedric> parcontre ca a un probleme, la taille des objets de tes paquets est limite par la taille de ton objet edje parent +06:40 < glouglou> cedric: mais un smart object dans un edje object qui est ensuite mappe, juste pour faire un trait, ca va etre un peu lourd non ? +06:40 < glouglou> et complexe +06:40 < glouglou> mais c'est vrai que ca resous mon probleme +06:41 <@cedric> bah, de toute facon, tu vas avoir une surface cree pour mettre ton edje dans ta map +06:41 <@cedric> dc ca reviendra au meme voir tu fairas l'economie d'une surface +06:49 < glouglou> cedric: donc quand tu swallow un evas smart object dans un edje object, les coordonnes pour le smart object sont relatifs a la part swallow ? +06:50 < glouglou> genre si je fais un geometry_get dans mon smart obj, le 0x0 sera en fait en haut a gauche de ma part swallow edje ? +06:52 <@cedric> oui +06:52 < glouglou> mais c'est magnifique +06:52 < glouglou> et splendide a fois +06:53 < glouglou> merci :D + +TODO LATER +========== + * find a better storage type for vertices quick access O(1) -> table possibility to foreach and remove at the same time -- cgit v1.2.3-59-g8ed1b From 717346d10e4eb79f5a5e78f1f29ab5b278784b2d Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 14 Dec 2012 10:21:15 +0100 Subject: notes about zooming, from zmike --- doc/TODO.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/TODO.txt b/doc/TODO.txt index 6353ec8..beed508 100644 --- a/doc/TODO.txt +++ b/doc/TODO.txt @@ -26,6 +26,21 @@ it seems to be always the same node numbers that gets this wrong edge * BUG: EGRAPH_LAYOUT_FRUCHTERMANREINGOLD is broken when adding many edges * zoom +10:16 < glouglou> i want to implement zooming with mouse scroll, do you have some ideas about that ? +10:16 < zmike> that should be trivial +10:16 < zmike> just hook mouse wheel and use efx_zoom +10:18 < glouglou> does efx_zoom resize the objects ? +10:18 < glouglou> all the graph is one evas smart object +10:18 < zmike> it does not resize, it just maps +10:18 < glouglou> that clips everything +10:18 < zmike> it should work, you can see the elm test is working, and that uses smart objects +10:18 < glouglou> yeah i want to update the coordinates i guess, not really "zoom" +10:19 < zmike> hm there's no efx_scale yet, but you could use efx_resize I would think +10:19 < glouglou> i would prefer to resize / update the coords +10:19 < glouglou> scale yes, that would be it +10:19 < glouglou> ok +10:19 < zmike> just calculate the size you want and use efx_resize +10:20 < zmike> it will animate the resizing * blobs 05:17 < glouglou> cedric: t'as vu dans ma demo les packets qui vont d'une node a l'autre quand les nodes bougent et ben les paquets arrivent a l'ancien endroit -- cgit v1.2.3-59-g8ed1b From 7157be1141bfa6d63eee94226bcd4bba3639abd0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 15 Dec 2012 01:08:40 +0100 Subject: update Thanks --- README | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README b/README index 7f3b14f..dc4be18 100644 --- a/README +++ b/README @@ -34,9 +34,10 @@ Thanks ====== Thanks to ntamas (http://sixdegrees.hu/) for her advices on igraph. +Thanks to cedric for tech advices on evas / edje. +Thanks to vtorri for tech advices on evas / edje. +Thanks to zmike for tech advices on efx. Thanks to raster for tech advices on evas / elementary. -Thanks to cedric for tech advices on evas / edge. -Thanks to vtorri for tech advices on evas / edge. Thanks to ludivina for graphical advices. History -- cgit v1.2.3-59-g8ed1b From 1d2344515cc3e50ff3ac97504dda58ecd38cb4fa Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 15 Dec 2012 08:04:18 +0100 Subject: increase vertice name max len (EGRAPH_VERTICE_NAME_MAXLEN) --- Egraph.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Egraph.h b/Egraph.h index 7f4d6c5..553d5cd 100644 --- a/Egraph.h +++ b/Egraph.h @@ -4,7 +4,7 @@ #include #define EGRAPH_VERTICES_MAX 16384 /* cannot be more that u_int32_t */ -#define EGRAPH_VERTICE_NAME_MAXLEN 50 +#define EGRAPH_VERTICE_NAME_MAXLEN 60 typedef struct Egraph Egraph; typedef struct Egraph_Edge Egraph_Edge; -- cgit v1.2.3-59-g8ed1b From 6cf2279fbf90c5fc51c5e9ca63789d9e2c8d148e Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sat, 15 Dec 2012 08:25:34 +0100 Subject: move 2 printfs to be DEBUG conditionnal --- egraph.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/egraph.c b/egraph.c index 990c9ce..bffcebf 100644 --- a/egraph.c +++ b/egraph.c @@ -690,14 +690,16 @@ _vertice_geometry_update(Egraph *eg, Egraph_Vertice *v) int w, h; edje_object_size_min_calc(v->o, &w, &h); - printf("_vertice_geometry_update: %d %d\n", w, h); + if (DEBUG) + printf("_vertice_geometry_update: %d %d\n", w, h); evas_object_resize(v->o, w, h); if (w > eg->vertice_max_w) eg->vertice_max_w = w; if (h > eg->vertice_max_h) eg->vertice_max_h = h; - printf("_vertice_geometry_update: end %d %d\n", - eg->vertice_max_w, eg->vertice_max_h); + if (DEBUG) + printf("_vertice_geometry_update: end %d %d\n", + eg->vertice_max_w, eg->vertice_max_h); } void -- cgit v1.2.3-59-g8ed1b From 917918db7044bd09a453d0d231537c9994d7d44f Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 16 Dec 2012 04:24:07 +0100 Subject: evas lockup ++ --- doc/bug_lockup_evas.txt | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index b7afa30..93b8395 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -509,3 +509,66 @@ rect_list_add_split_fuzzy (node=0xb07d60, rects=0x692668, [0/1873 #16 0x00007ffff50e8b27 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 #17 0x00000000004025d9 in elm_main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:324 #18 0x0000000000402624 in main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:331 + +=============================================================================== +2012-12-16_04-22 + +happened AFTER raster's fix +------------------------------------------------------------------------ +r81039 | raster | 2012-12-16 03:01:11 +0100 (Sun, 16 Dec 2012) | 5 lines +small change - dont let update rect list for image object become a +runaway endless list if evas doenst come around and render (pick it +up) any time soon - limit to 512 update rects. + + +^C +Program received signal SIGINT, Interrupt. +0x00007ffff53ddc54 in _calc_intra_outer_rect_area (outer=, + intra=, a=..., b=...) at lib/evas/common/evas_tiler.c:530 +530 outer->height = max_bottom - min_top; +(gdb) bt +#0 0x00007ffff53ddc54 in _calc_intra_outer_rect_area ( + outer=, intra=, a=..., b=...) + at lib/evas/common/evas_tiler.c:530 +#1 rect_list_add_split_fuzzy (node=0x9d27c0, rects=0x6942b8, + accepted_error=) at lib/evas/common/evas_tiler.c:652 +#2 rect_list_add_split_fuzzy_and_merge (node=0x9d27c0, rects=0x6942b8, + split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#3 _add_redraw (h=76, w=276, y=453, x=990, rects=0x6942b8) + at lib/evas/common/evas_tiler.c:956 +#4 evas_common_tilebuf_add_redraw (tb=0x694280, x=990, y=453, w=276, h=76) + at lib/evas/common/evas_tiler.c:986 +#5 0x00007ffff539736f in _evas_render_prev_cur_clip_cache_add (obj=obj@entry= + 0xbee890, e=0x68b390, e=0x68b390) at lib/evas/canvas/evas_render.c:158 +#6 0x00007ffff539ba0c in _evas_render_phase1_direct (render_objects=0xbee800, + active_objects=0x68b390, e=, + restack_objects=, delete_objects=) + at lib/evas/canvas/evas_render.c:257 +#7 evas_render_updates_internal (eo_e=0x68b300, + make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') + at lib/evas/canvas/evas_render.c:1357 +#8 0x00007ffff539d9c7 in _canvas_render_updates (eo_e=, + _pd=, list=) + at lib/evas/canvas/evas_render.c:1795 +#9 0x00007ffff706fa45 in _eo_op_internal (obj=0x68b300, op_type= + EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe1f8) at lib/eo/eo.c:363 +#10 0x00007ffff70716dd in _eo_dov_internal (p_list=0x7fffffffe1f8, op_type= + EO_OP_TYPE_REGULAR, obj=0x68b300) at lib/eo/eo.c:403 +#11 eo_do_internal (obj=0x68b300, op_type=op_type@entry=EO_OP_TYPE_REGULAR) + at lib/eo/eo.c:434 +#12 0x00007ffff539d94f in evas_render_updates (eo_e=) + at lib/evas/canvas/evas_render.c:1779 +#13 0x00007fffe6f7743a in _ecore_evas_x_render (ee=0x689b80) + at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#14 0x00007ffff6e5e841 in _ecore_evas_idle_enter (data=) + at lib/ecore_evas/ecore_evas.c:59 +#15 0x00007ffff50e5059 in _ecore_call_task_cb (data=, + func=) at lib/ecore/ecore_private.h:300 +#16 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#17 0x00007ffff50e74bb in _ecore_main_loop_iterate_internal ( + once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1866 +#18 0x00007ffff50e7b67 in ecore_main_loop_begin () at lib/ecore/ecore_main.c:964 +#19 0x00000000004035b0 in elm_main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:461 +---Type to continue, or q to quit--- +#20 0x00000000004035fb in main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:468 -- cgit v1.2.3-59-g8ed1b From 54cb0d42081e3b411ee5b4f56f84d4af7b7062d8 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 16 Dec 2012 04:29:06 +0100 Subject: more details --- doc/bug_lockup_evas.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index 93b8395..27eaf50 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -1,3 +1,4 @@ +=============================================================================== This bug is a lockup of evas during rendering in my efl app. App freeze and takes 100% CPU. Below are backtraces when gdb was running and I interrupt it with Ctrl-C. @@ -513,6 +514,17 @@ rect_list_add_split_fuzzy (node=0xb07d60, rects=0x692668, [0/1873 =============================================================================== 2012-12-16_04-22 +This bug is a lockup of evas during rendering in my efl app. +App freeze and takes 100% CPU. Below are backtraces when gdb was running and +I interrupt it with Ctrl-C. + +At the time of crash, around 300objects total : +elementary interface + ~100 edje + 100 edje mapped with evas_map + ~100 evas_object_text + +This crash is not predictible from what I see, sometimes it goes fine for a long +time. +It seem to crash more when using more edje objects. + happened AFTER raster's fix ------------------------------------------------------------------------ r81039 | raster | 2012-12-16 03:01:11 +0100 (Sun, 16 Dec 2012) | 5 lines -- cgit v1.2.3-59-g8ed1b From e98416a88ca59b0d3a9e523eed53323b0e5d353c Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 16 Dec 2012 18:17:28 +0100 Subject: lockup ++ --- doc/bug_lockup_evas.txt | 60 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/doc/bug_lockup_evas.txt b/doc/bug_lockup_evas.txt index 27eaf50..4f194c5 100644 --- a/doc/bug_lockup_evas.txt +++ b/doc/bug_lockup_evas.txt @@ -584,3 +584,63 @@ Program received signal SIGINT, Interrupt. #19 0x00000000004035b0 in elm_main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:461 ---Type to continue, or q to quit--- #20 0x00000000004035fb in main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:468 + +=============================================================================== +2012-12-16_18-16 + + +^C +Program received signal SIGINT, Interrupt. +0x00007ffff53ddd20 in _calc_intra_outer_rect_area (outer=, + intra=, a=..., b=...) + at lib/evas/common/evas_tiler.c:509 +509 if (a.bottom < b.bottom) +(gdb) bt +#0 0x00007ffff53ddd20 in _calc_intra_outer_rect_area ( + outer=, intra=, a=..., b=...) + at lib/evas/common/evas_tiler.c:509 +#1 rect_list_add_split_fuzzy (node=0x16b03d0, rects=0x692668, + accepted_error=) at lib/evas/common/evas_tiler.c:652 +#2 rect_list_add_split_fuzzy_and_merge (node=0x16b03d0, rects=0x692668, + split_accepted_error=, merge_accepted_error=) + at lib/evas/common/evas_tiler.c:849 +#3 _add_redraw (h=31, w=323, y=264, x=696, rects=0x692668) + at lib/evas/common/evas_tiler.c:956 +#4 evas_common_tilebuf_add_redraw (tb=0x692630, x=696, y=264, w=323, h=31) + at lib/evas/common/evas_tiler.c:986 +#5 0x00007ffff539736f in _evas_render_prev_cur_clip_cache_add (obj=obj@entry= + 0x36cef40, e=0x689740, e=0x689740) at lib/evas/canvas/evas_render.c:158 +#6 0x00007ffff539ba0c in _evas_render_phase1_direct (render_objects= + 0x36ceeb0, active_objects=0x689740, e=, + restack_objects=, delete_objects=) + at lib/evas/canvas/evas_render.c:257 +#7 evas_render_updates_internal (eo_e=0x6896b0, + make_updates=make_updates@entry=1 '\001', do_draw=do_draw@entry=1 '\001') + at lib/evas/canvas/evas_render.c:1357 +#8 0x00007ffff539d9c7 in _canvas_render_updates (eo_e=, + _pd=, list=) + at lib/evas/canvas/evas_render.c:1795 +#9 0x00007ffff706fa45 in _eo_op_internal (obj=0x6896b0, op_type= + EO_OP_TYPE_REGULAR, op=402, p_list=0x7fffffffe1f8) at lib/eo/eo.c:363 +#10 0x00007ffff70716dd in _eo_dov_internal (p_list=0x7fffffffe1f8, op_type= + EO_OP_TYPE_REGULAR, obj=0x6896b0) at lib/eo/eo.c:403 +#11 eo_do_internal (obj=0x6896b0, op_type=op_type@entry=EO_OP_TYPE_REGULAR) + at lib/eo/eo.c:434 +#12 0x00007ffff539d94f in evas_render_updates (eo_e=) + at lib/evas/canvas/evas_render.c:1779 +#13 0x00007fffe6f7743a in _ecore_evas_x_render (ee=0x687f30) + at modules/ecore_evas/engines/x/ecore_evas_x.c:447 +#14 0x00007ffff6e5e841 in _ecore_evas_idle_enter (data=) + at lib/ecore_evas/ecore_evas.c:59 +#15 0x00007ffff50e5059 in _ecore_call_task_cb (data=, + func=) at lib/ecore/ecore_private.h:300 +#16 _ecore_idle_enterer_call () at lib/ecore/ecore_idle_enterer.c:235 +#17 0x00007ffff50e766d in _ecore_main_loop_iterate_internal ( + once_only=once_only@entry=0) at lib/ecore/ecore_main.c:1841 +#18 0x00007ffff50e7b67 in ecore_main_loop_begin () + at lib/ecore/ecore_main.c:964 +#19 0x00000000004031c1 in elm_main (argc=1, argv=0x7fffffffe5b8) + at gg_map.c:447 +#20 0x000000000040320c in main (argc=1, argv=0x7fffffffe5b8) at gg_map.c:454 + + -- cgit v1.2.3-59-g8ed1b From 9430eeadb7e84e5e921b5f086b15eb61116197e4 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Wed, 27 Feb 2013 19:51:47 +0100 Subject: remove old file --- gg_elife/in_separate_git.txt | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 gg_elife/in_separate_git.txt diff --git a/gg_elife/in_separate_git.txt b/gg_elife/in_separate_git.txt deleted file mode 100644 index 6bdc618..0000000 --- a/gg_elife/in_separate_git.txt +++ /dev/null @@ -1,6 +0,0 @@ -git clone git@gouloum.fr:elife - -cd elife -./configure --enable-glouglou -make -sudo make install -- cgit v1.2.3-59-g8ed1b From 725fb8f08f5a430aa34ce5538c9bbf54c48150a0 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Fri, 1 Mar 2013 13:20:47 +0100 Subject: gg_sniff: replace tabs by 2 spaces no functionnal change --- gg_sniff/pcap.c | 776 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 388 insertions(+), 388 deletions(-) diff --git a/gg_sniff/pcap.c b/gg_sniff/pcap.c index fd9470f..72b9133 100644 --- a/gg_sniff/pcap.c +++ b/gg_sniff/pcap.c @@ -46,8 +46,8 @@ #define CONNTIMER 5 // XXX conf ? struct phandler { - pcap_handler f; - int type; + pcap_handler f; + int type; }; struct _cap_t { @@ -63,20 +63,20 @@ struct _cap_t { }; static pcap_t *my_pcap_open_live(const char *, int, int, int, - char *, u_int, u_int); + char *, u_int, u_int); static void ip_handle(struct ip *, const u_char *, u_int); static void conn_del(struct ggnet_conn *); static void ether_handle(struct ether_header *, const u_char *, u_int); static pcap_handler lookup_phandler(int); static void phandler_ether(u_char *, - const struct pcap_pkthdr *, const u_char *); + const struct pcap_pkthdr *, const u_char *); #if defined(__OpenBSD__) static void phandler_loop(u_char *, - const struct pcap_pkthdr *, const u_char *); + const struct pcap_pkthdr *, const u_char *); #endif #if defined(__linux__) static void phandler_sll(u_char *, - const struct pcap_pkthdr *, const u_char *); + const struct pcap_pkthdr *, const u_char *); #endif static void cb_pcap(int, short, void *); static void cb_conntimer(int, short, void *); @@ -96,46 +96,46 @@ static struct phandler phandlers[] = { static struct _cap_t _cap; -int + int ggsniff_pcap_init(struct event_base *ev_base, struct gg_client *ggcli, - struct ggnet *net, char *iface, int active) + struct ggnet *net, char *iface, int active) { - char errbuf[PCAP_ERRBUF_SIZE]; - struct bpf_program bprog; + char errbuf[PCAP_ERRBUF_SIZE]; + struct bpf_program bprog; pcap_t *pcap; #if defined(__OpenBSD__) if (!iface) err(1, "On OpenBSD you cannot listen on ANY interface"); #endif - pcap = my_pcap_open_live(iface, PCAP_SNAPLEN, 1, PCAP_TO, - errbuf, -1, 0); - if (pcap == NULL) - err(1, "capture: pcap_open_live failed on interface %s\n" - "with snaplen %d : %s", - iface, PCAP_SNAPLEN, errbuf); - if (pcap_compile(pcap, &bprog, PCAP_FILTER, 0, 0) < 0) - err(1, "capture: pcap_compile failed with filter %s : %s", - PCAP_FILTER, pcap_geterr(pcap)); - if (pcap_setfilter(pcap, &bprog) < 0) - err(1, "capture: pcap_setfilter failed : %s", - pcap_geterr(pcap)); - - _cap.pcap = pcap; - _cap.handler = lookup_phandler(pcap_datalink(pcap)); - //_cap.tv.tv_sec = 0; - //_cap.tv.tv_usec = PCAP_TO; - fd_nonblock(pcap_fileno(pcap)); + pcap = my_pcap_open_live(iface, PCAP_SNAPLEN, 1, PCAP_TO, + errbuf, -1, 0); + if (pcap == NULL) + err(1, "capture: pcap_open_live failed on interface %s\n" + "with snaplen %d : %s", + iface, PCAP_SNAPLEN, errbuf); + if (pcap_compile(pcap, &bprog, PCAP_FILTER, 0, 0) < 0) + err(1, "capture: pcap_compile failed with filter %s : %s", + PCAP_FILTER, pcap_geterr(pcap)); + if (pcap_setfilter(pcap, &bprog) < 0) + err(1, "capture: pcap_setfilter failed : %s", + pcap_geterr(pcap)); + + _cap.pcap = pcap; + _cap.handler = lookup_phandler(pcap_datalink(pcap)); + //_cap.tv.tv_sec = 0; + //_cap.tv.tv_usec = PCAP_TO; + fd_nonblock(pcap_fileno(pcap)); _cap.ev = event_new(ev_base, pcap_fileno(pcap), EV_READ|EV_PERSIST, - cb_pcap, NULL); + cb_pcap, NULL); //event_add(_cap.ev, &_cap->tv); event_add(_cap.ev, NULL); - _cap.conntimer_tv.tv_sec = CONNTIMER; - _cap.conntimer_tv.tv_usec = 0; - _cap.conntimer_ev = evtimer_new(ev_base, cb_conntimer, NULL); - if (evtimer_add(_cap.conntimer_ev, &_cap.conntimer_tv) == -1) - gg_log_fatal("user: event_add conntimer failed: %s", strerror(errno)); + _cap.conntimer_tv.tv_sec = CONNTIMER; + _cap.conntimer_tv.tv_usec = 0; + _cap.conntimer_ev = evtimer_new(ev_base, cb_conntimer, NULL); + if (evtimer_add(_cap.conntimer_ev, &_cap.conntimer_tv) == -1) + gg_log_fatal("user: event_add conntimer failed: %s", strerror(errno)); if (active) ggnet_set_dns(net, 1, ev_base, cb_nodename); @@ -143,10 +143,10 @@ ggsniff_pcap_init(struct event_base *ev_base, struct gg_client *ggcli, _cap.ggcli = ggcli; _cap.net = net; - return 1; + return 1; } -void + void ggsniff_pcap_shutdown(void) { event_del(_cap.ev); @@ -160,125 +160,125 @@ ggsniff_pcap_shutdown(void) * based on OpenBSD tcpdump, privsep_pcap.c v1.16 */ -static pcap_t * + static pcap_t * my_pcap_open_live(const char *dev, int slen, int promisc, int to_ms, - char *ebuf, u_int dlt, u_int dirfilt) + char *ebuf, u_int dlt, u_int dirfilt) { #if defined(__OpenBSD__) - struct bpf_version bv; - u_int v; - pcap_t *p; - char bpf[sizeof "/dev/bpf0000000000"]; - int fd, n = 0; - struct ifreq ifr; - - p = xmalloc(sizeof(*p)); - bzero(p, sizeof(*p)); - - /* priv part */ - - do { - snprintf(bpf, sizeof(bpf), "/dev/bpf%d", n++); - fd = open(bpf, O_RDONLY); - } while (fd < 0 && errno == EBUSY); - if (fd < 0) - return NULL; - - v = 32768; /* XXX this should be a user-accessible hook */ - ioctl(fd, BIOCSBLEN, &v); - - strlcpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); - if (ioctl(fd, BIOCSETIF, &ifr) < 0) - return NULL; - - if (dlt != (u_int) -1 && ioctl(fd, BIOCSDLT, &dlt)) - return NULL; - - if (promisc) - /* this is allowed to fail */ - ioctl(fd, BIOCPROMISC, NULL); - if (ioctl(fd, BIOCSDIRFILT, &dirfilt) < 0) - return NULL; - - /* lock the descriptor */ - if (ioctl(fd, BIOCLOCK, NULL) < 0) - return NULL; - - /* end of priv part */ - - /* fd is locked, can only use 'safe' ioctls */ - if (ioctl(fd, BIOCVERSION, &bv) < 0) { - snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCVERSION: %s", - pcap_strerror(errno)); - return NULL; - } - - if (bv.bv_major != BPF_MAJOR_VERSION || - bv.bv_minor < BPF_MINOR_VERSION) { - snprintf(ebuf, PCAP_ERRBUF_SIZE, - "kernel bpf filter out of date"); - return NULL; - } - - p->fd = fd; - p->snapshot = slen; - - /* Get the data link layer type. */ - if (ioctl(fd, BIOCGDLT, &v) < 0) { - snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGDLT: %s", - pcap_strerror(errno)); - return NULL; - } + struct bpf_version bv; + u_int v; + pcap_t *p; + char bpf[sizeof "/dev/bpf0000000000"]; + int fd, n = 0; + struct ifreq ifr; + + p = xmalloc(sizeof(*p)); + bzero(p, sizeof(*p)); + + /* priv part */ + + do { + snprintf(bpf, sizeof(bpf), "/dev/bpf%d", n++); + fd = open(bpf, O_RDONLY); + } while (fd < 0 && errno == EBUSY); + if (fd < 0) + return NULL; + + v = 32768; /* XXX this should be a user-accessible hook */ + ioctl(fd, BIOCSBLEN, &v); + + strlcpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); + if (ioctl(fd, BIOCSETIF, &ifr) < 0) + return NULL; + + if (dlt != (u_int) -1 && ioctl(fd, BIOCSDLT, &dlt)) + return NULL; + + if (promisc) + /* this is allowed to fail */ + ioctl(fd, BIOCPROMISC, NULL); + if (ioctl(fd, BIOCSDIRFILT, &dirfilt) < 0) + return NULL; + + /* lock the descriptor */ + if (ioctl(fd, BIOCLOCK, NULL) < 0) + return NULL; + + /* end of priv part */ + + /* fd is locked, can only use 'safe' ioctls */ + if (ioctl(fd, BIOCVERSION, &bv) < 0) { + snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCVERSION: %s", + pcap_strerror(errno)); + return NULL; + } + + if (bv.bv_major != BPF_MAJOR_VERSION || + bv.bv_minor < BPF_MINOR_VERSION) { + snprintf(ebuf, PCAP_ERRBUF_SIZE, + "kernel bpf filter out of date"); + return NULL; + } + + p->fd = fd; + p->snapshot = slen; + + /* Get the data link layer type. */ + if (ioctl(fd, BIOCGDLT, &v) < 0) { + snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGDLT: %s", + pcap_strerror(errno)); + return NULL; + } #if _BSDI_VERSION - 0 >= 199510 - /* The SLIP and PPP link layer header changed in BSD/OS 2.1 */ - switch (v) { + /* The SLIP and PPP link layer header changed in BSD/OS 2.1 */ + switch (v) { - case DLT_SLIP: - v = DLT_SLIP_BSDOS; - break; + case DLT_SLIP: + v = DLT_SLIP_BSDOS; + break; - case DLT_PPP: - v = DLT_PPP_BSDOS; - break; - } + case DLT_PPP: + v = DLT_PPP_BSDOS; + break; + } #endif - p->linktype = v; - - /* XXX hack from tcpdump */ - if (p->linktype == DLT_PFLOG && p->snapshot < 160) - p->snapshot = 160; - - /* set timeout */ - if (to_ms != 0) { - struct timeval to; - to.tv_sec = to_ms / 1000; - to.tv_usec = (to_ms * 1000) % 1000000; - if (ioctl(p->fd, BIOCSRTIMEOUT, &to) < 0) { - snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCSRTIMEOUT: %s", - pcap_strerror(errno)); - return NULL; - } - } - - if (ioctl(fd, BIOCGBLEN, &v) < 0) { - snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGBLEN: %s", - pcap_strerror(errno)); - return NULL; - } - p->bufsize = v; - p->buffer = (u_char *)malloc(p->bufsize); - if (p->buffer == NULL) { - snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s", - pcap_strerror(errno)); - return NULL; - } - return p; + p->linktype = v; + + /* XXX hack from tcpdump */ + if (p->linktype == DLT_PFLOG && p->snapshot < 160) + p->snapshot = 160; + + /* set timeout */ + if (to_ms != 0) { + struct timeval to; + to.tv_sec = to_ms / 1000; + to.tv_usec = (to_ms * 1000) % 1000000; + if (ioctl(p->fd, BIOCSRTIMEOUT, &to) < 0) { + snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCSRTIMEOUT: %s", + pcap_strerror(errno)); + return NULL; + } + } + + if (ioctl(fd, BIOCGBLEN, &v) < 0) { + snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCGBLEN: %s", + pcap_strerror(errno)); + return NULL; + } + p->bufsize = v; + p->buffer = (u_char *)malloc(p->bufsize); + if (p->buffer == NULL) { + snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s", + pcap_strerror(errno)); + return NULL; + } + return p; #else /* defined(__OpenBSD__) */ return pcap_open_live(dev, slen, promisc, to_ms, ebuf); #endif } -static void + static void cb_pcap(int fd, short why, void *data) { gg_log_tmp("cb_pcap"); @@ -289,49 +289,49 @@ cb_pcap(int fd, short why, void *data) // gg_log_fatal("user: event_add pcap failed : %s", strerror(errno)); } -static void + static void cb_conntimer(int fd, short why, void *data) { - struct ggnet_conn *c, *ctmp; - struct ggnet_node *n, *ntmp; - int i, to; - - gg_log_debug("ev_timer"); - ggnet_time_update(_cap.net, time(NULL)); - - i = 0; - LIST_FOREACH_SAFE(c, &_cap.net->conn_list, entry, ctmp) { - switch (c->proto) { - case IPPROTO_UDP: - to = CONN_TIMEOUT_UDP; - break; - case IPPROTO_ICMP: - to = CONN_TIMEOUT_ICMP; - break; - default: - to = CONN_TIMEOUT; - break; - } - if (_cap.net->time > c->lastseen + to) - conn_del(c); - else - i++; - } - - if (_cap.net->node_count > NODE_MAX_WITHOUT_TIMEOUT) { - LIST_FOREACH_SAFE(n, &_cap.net->node_list, entry, ntmp) { - if (n->used == 0 && - _cap.net->time > n->lastseen + NODE_TIMEOUT) - ggnet_node_del(_cap.net, n); - } - } - - gg_log_debug("user: ev_timer leaving with %d active connections and %d active nodes", i, _cap.net->node_count); - if (evtimer_add(_cap.conntimer_ev, &_cap.conntimer_tv) == -1) - gg_log_fatal("user: event_add conntimer failed : %s", strerror(errno)); + struct ggnet_conn *c, *ctmp; + struct ggnet_node *n, *ntmp; + int i, to; + + gg_log_debug("ev_timer"); + ggnet_time_update(_cap.net, time(NULL)); + + i = 0; + LIST_FOREACH_SAFE(c, &_cap.net->conn_list, entry, ctmp) { + switch (c->proto) { + case IPPROTO_UDP: + to = CONN_TIMEOUT_UDP; + break; + case IPPROTO_ICMP: + to = CONN_TIMEOUT_ICMP; + break; + default: + to = CONN_TIMEOUT; + break; + } + if (_cap.net->time > c->lastseen + to) + conn_del(c); + else + i++; + } + + if (_cap.net->node_count > NODE_MAX_WITHOUT_TIMEOUT) { + LIST_FOREACH_SAFE(n, &_cap.net->node_list, entry, ntmp) { + if (n->used == 0 && + _cap.net->time > n->lastseen + NODE_TIMEOUT) + ggnet_node_del(_cap.net, n); + } + } + + gg_log_debug("user: ev_timer leaving with %d active connections and %d active nodes", i, _cap.net->node_count); + if (evtimer_add(_cap.conntimer_ev, &_cap.conntimer_tv) == -1) + gg_log_fatal("user: event_add conntimer failed : %s", strerror(errno)); } -static void + static void cb_nodename(struct ggnet *net, struct ggnet_node *n) { struct gg_packet pkt; @@ -358,153 +358,153 @@ cb_nodename(struct ggnet *net, struct ggnet_node *n) #define NOTRECEIVED(v) (wirelen < sizeof(v)) #define log_pinvalid(fmt, ...) \ gg_log_info("ggsniff pinvalid: " fmt, ##__VA_ARGS__) -static void + static void ip_handle(struct ip *ip, const u_char *pend, u_int wirelen) { - u_int len, ip_hlen, off; - const u_char *cp; - struct tcphdr *tcph; - struct udphdr *udph; - struct icmp *icmp; - struct in_addr src, dst; - u_int src_port, dst_port; - u_int proto, close; - int response; - struct ggnet_conn *conn; - struct gg_packet pkt; - - if (NOTCAPTURED(ip)) { - log_pinvalid("user: ip truncated (ip %x pend %x sizeof(ip) %d", + u_int len, ip_hlen, off; + const u_char *cp; + struct tcphdr *tcph; + struct udphdr *udph; + struct icmp *icmp; + struct in_addr src, dst; + u_int src_port, dst_port; + u_int proto, close; + int response; + struct ggnet_conn *conn; + struct gg_packet pkt; + + if (NOTCAPTURED(ip)) { + log_pinvalid("user: ip truncated (ip %x pend %x sizeof(ip) %d", ip, pend, sizeof(ip)); - _cap.ptruncated++; - return; - } - - if (ip->ip_v != IPVERSION) { - log_pinvalid("user: invalid ip version"); - _cap.pinvalid++; - return; - } - - len = ntohs(ip->ip_len); - if (wirelen < len) { - log_pinvalid("user: ip too small"); - _cap.pinvalid++; - len = wirelen; - } - - ip_hlen = ip->ip_hl * 4; - if (ip_hlen < sizeof(struct ip) || ip_hlen > len) { - log_pinvalid("user: ip_hlen invalid, %d", ip_hlen); - _cap.pinvalid++; - return; - } - len -= ip_hlen; - - src.s_addr = ntohl(ip->ip_src.s_addr); - dst.s_addr = ntohl(ip->ip_dst.s_addr); - src_port = 0; - dst_port = 0; - proto = IPPROTO_IP; - close = 0; - - off = ntohs(ip->ip_off); - if ((off & IP_OFFMASK) == 0) { - cp = (const u_char *)ip + ip_hlen; - switch (ip->ip_p) { - - case IPPROTO_TCP: - tcph = (struct tcphdr *)cp; - if (NOTCAPTURED(&tcph->th_flags)) { - log_pinvalid("user: tcp truncated"); - _cap.ptruncated++; - return; - } - if (NOTRECEIVED(*tcph)) { - log_pinvalid("user: tcp too small"); - _cap.pinvalid++; - return; - } - src_port = ntohs(tcph->th_sport); - dst_port = ntohs(tcph->th_dport); - proto = IPPROTO_TCP; - if ((tcph->th_flags & TH_FIN) && - (tcph->th_flags & TH_ACK)) - close = 1; - break; - - case IPPROTO_UDP: - udph = (struct udphdr *)cp; - if (NOTCAPTURED(&udph->uh_dport)) { - log_pinvalid("user: udp truncated, " - "ip %x, udph %x, uh_port %x, pend %x, ip_hlen %d", - ip, udph, &udph->uh_dport, pend, ip_hlen); - _cap.ptruncated++; - return; - } - if (NOTRECEIVED(*udph)) { - log_pinvalid("user: udp too small"); - _cap.pinvalid++; - return; - } - src_port = ntohs(udph->uh_sport); - dst_port = ntohs(udph->uh_dport); - proto = IPPROTO_UDP; - break; - - case IPPROTO_ICMP: - icmp = (struct icmp *)cp; - if (NOTRECEIVED(*icmp)) { - log_pinvalid("user: icmp too small"); - _cap.pinvalid++; - return; - } - proto = IPPROTO_ICMP; - break; - - default: - gg_log_warn("user: unknown ip protocol !"); - break; - } - } else { - /* - * if this isn't the first frag, we're missing the - * next level protocol header. - */ - gg_log_tmp("user: got a fragmented ip packet !"); - } + _cap.ptruncated++; + return; + } + + if (ip->ip_v != IPVERSION) { + log_pinvalid("user: invalid ip version"); + _cap.pinvalid++; + return; + } + + len = ntohs(ip->ip_len); + if (wirelen < len) { + log_pinvalid("user: ip too small"); + _cap.pinvalid++; + len = wirelen; + } + + ip_hlen = ip->ip_hl * 4; + if (ip_hlen < sizeof(struct ip) || ip_hlen > len) { + log_pinvalid("user: ip_hlen invalid, %d", ip_hlen); + _cap.pinvalid++; + return; + } + len -= ip_hlen; + + src.s_addr = ntohl(ip->ip_src.s_addr); + dst.s_addr = ntohl(ip->ip_dst.s_addr); + src_port = 0; + dst_port = 0; + proto = IPPROTO_IP; + close = 0; + + off = ntohs(ip->ip_off); + if ((off & IP_OFFMASK) == 0) { + cp = (const u_char *)ip + ip_hlen; + switch (ip->ip_p) { + + case IPPROTO_TCP: + tcph = (struct tcphdr *)cp; + if (NOTCAPTURED(&tcph->th_flags)) { + log_pinvalid("user: tcp truncated"); + _cap.ptruncated++; + return; + } + if (NOTRECEIVED(*tcph)) { + log_pinvalid("user: tcp too small"); + _cap.pinvalid++; + return; + } + src_port = ntohs(tcph->th_sport); + dst_port = ntohs(tcph->th_dport); + proto = IPPROTO_TCP; + if ((tcph->th_flags & TH_FIN) && + (tcph->th_flags & TH_ACK)) + close = 1; + break; + + case IPPROTO_UDP: + udph = (struct udphdr *)cp; + if (NOTCAPTURED(&udph->uh_dport)) { + log_pinvalid("user: udp truncated, " + "ip %x, udph %x, uh_port %x, pend %x, ip_hlen %d", + ip, udph, &udph->uh_dport, pend, ip_hlen); + _cap.ptruncated++; + return; + } + if (NOTRECEIVED(*udph)) { + log_pinvalid("user: udp too small"); + _cap.pinvalid++; + return; + } + src_port = ntohs(udph->uh_sport); + dst_port = ntohs(udph->uh_dport); + proto = IPPROTO_UDP; + break; + + case IPPROTO_ICMP: + icmp = (struct icmp *)cp; + if (NOTRECEIVED(*icmp)) { + log_pinvalid("user: icmp too small"); + _cap.pinvalid++; + return; + } + proto = IPPROTO_ICMP; + break; + + default: + gg_log_warn("user: unknown ip protocol !"); + break; + } + } else { + /* + * if this isn't the first frag, we're missing the + * next level protocol header. + */ + gg_log_tmp("user: got a fragmented ip packet !"); + } pkt.ver = PACKET_VERSION; conn = ggnet_conn_find(_cap.net, &src, src_port, &dst, dst_port, - proto, &response); - if (conn) { - if (!close) { - pkt.type = PACKET_DATA; - pkt.data_connid = conn->id; - GG_PKTDATA_SIZE_ENCODE(pkt.data_size, ip->ip_len, response); + proto, &response); + if (conn) { + if (!close) { + pkt.type = PACKET_DATA; + pkt.data_connid = conn->id; + GG_PKTDATA_SIZE_ENCODE(pkt.data_size, ip->ip_len, response); gg_client_send(_cap.ggcli, &pkt); - ggnet_conn_data(_cap.net, conn, ip->ip_len, response); - } else { - conn_del(conn); - } - } else { - if (!close) { - conn = ggnet_conn_add(_cap.net, &src, src_port, &dst, dst_port, proto, - ip->ip_len, -1); - pkt.type = PACKET_NEWCONN; - pkt.newconn_id = conn->id; - pkt.newconn_src = src.s_addr; - pkt.newconn_dst = dst.s_addr; - pkt.newconn_proto = proto; - GG_PKTDATA_SIZE_ENCODE(pkt.newconn_size, ip->ip_len, 0); + ggnet_conn_data(_cap.net, conn, ip->ip_len, response); + } else { + conn_del(conn); + } + } else { + if (!close) { + conn = ggnet_conn_add(_cap.net, &src, src_port, &dst, dst_port, proto, + ip->ip_len, -1); + pkt.type = PACKET_NEWCONN; + pkt.newconn_id = conn->id; + pkt.newconn_src = src.s_addr; + pkt.newconn_dst = dst.s_addr; + pkt.newconn_proto = proto; + GG_PKTDATA_SIZE_ENCODE(pkt.newconn_size, ip->ip_len, 0); gg_client_send(_cap.ggcli, &pkt); - } else { - gg_log_warn("user: captured connection close w/o open !"); - } - } + } else { + gg_log_warn("user: captured connection close w/o open !"); + } + } } -static void + static void conn_del(struct ggnet_conn *c) { struct gg_packet pkt; @@ -516,11 +516,11 @@ conn_del(struct ggnet_conn *c) ggnet_conn_del(_cap.net, c); } -static void + static void ether_handle(struct ether_header *ether, const u_char *pend, u_int wirelen) { struct ip *ip; - u_short ether_type; + u_short ether_type; wirelen -= sizeof(struct ether_header); @@ -529,19 +529,19 @@ ether_handle(struct ether_header *ether, const u_char *pend, u_int wirelen) gg_log_tmp("llc packet !"); else { switch (ether_type) { - case ETHERTYPE_IP: - gg_log_tmp("loop family AF_LINK IP"); - ip = (struct ip *)((u_char *)ether + sizeof(struct ether_header)); - ip_handle(ip, pend, wirelen); - break; - default: - gg_log_tmp("loop non ip packet !"); - break; + case ETHERTYPE_IP: + gg_log_tmp("loop family AF_LINK IP"); + ip = (struct ip *)((u_char *)ether + sizeof(struct ether_header)); + ip_handle(ip, pend, wirelen); + break; + default: + gg_log_tmp("loop non ip packet !"); + break; } } } -static pcap_handler + static pcap_handler lookup_phandler(int type) { struct phandler *p; @@ -555,21 +555,21 @@ lookup_phandler(int type) return NULL; } -static void + static void phandler_ether(u_char *user, const struct pcap_pkthdr *h, const u_char *p) { - struct ether_header *ep; - const u_char *pend; - u_int len; + struct ether_header *ep; + const u_char *pend; + u_int len; - gg_log_debug("user: pcap handler ethernet !"); + gg_log_debug("user: pcap handler ethernet !"); - /* XXX here i assume that packets are alligned, which might not - * be the case when using dump files, says tcpdump sources */ + /* XXX here i assume that packets are alligned, which might not + * be the case when using dump files, says tcpdump sources */ - ep = (struct ether_header *)p; - pend = p + h->caplen; - len = h->len - sizeof(struct ether_header); + ep = (struct ether_header *)p; + pend = p + h->caplen; + len = h->len - sizeof(struct ether_header); ether_handle(ep, pend, len); } @@ -585,32 +585,32 @@ phandler_ether(u_char *user, const struct pcap_pkthdr *h, const u_char *p) #define LINUX_SLL_P_CAN 0x000C /* Controller Area Network */ #define LINUX_SLL_P_IRDA_LAP 0x0017 /* IrDA Link Access Protocol */ -static void + static void phandler_sll(u_char *user, const struct pcap_pkthdr *h, const u_char *p) { - struct ip *ip; - struct ether_header *ep; - u_int family; - const u_char *pend; - u_int len; + struct ip *ip; + struct ether_header *ep; + u_int family; + const u_char *pend; + u_int len; - gg_log_debug("user: phandler_sll !"); + gg_log_debug("user: phandler_sll !"); - /* XXX here i assume that packets are alligned, which might not - * be the case when using dump files, says tcpdump sources */ + /* XXX here i assume that packets are alligned, which might not + * be the case when using dump files, says tcpdump sources */ - pend = p + h->caplen; - len = h->len - SLL_HDR_LEN; + pend = p + h->caplen; + len = h->len - SLL_HDR_LEN; family = ntohs(p[14]); if (family < 1536) { /* linux and wireshark are good for you */ switch (family) { - case LINUX_SLL_P_ETHERNET: - ep = (struct ether_header *)((u_char *)p + SLL_HDR_LEN); - ether_handle(ep, pend, len); - default: - gg_log_tmp("unknown family %x !", family); - break; + case LINUX_SLL_P_ETHERNET: + ep = (struct ether_header *)((u_char *)p + SLL_HDR_LEN); + ether_handle(ep, pend, len); + default: + gg_log_tmp("unknown family %x !", family); + break; } } else { ip = (struct ip *)(p + SLL_HDR_LEN); @@ -625,38 +625,38 @@ phandler_sll(u_char *user, const struct pcap_pkthdr *h, const u_char *p) #if defined(__OpenBSD__) #define NULL_HDRLEN 4 -static void + static void phandler_loop(u_char *user, const struct pcap_pkthdr *h, const u_char *p) { - struct ip *ip; - struct ether_header *ep; - u_int family; - const u_char *pend; - u_int len; - - gg_log_debug("user: pcap handler loop !"); - - /* XXX here i assume that packets are alligned, which might not - * be the case when using dump files, says tcpdump sources */ - - pend = p + h->caplen; - len = h->len - NULL_HDRLEN; - - memcpy((char *)&family, (char *)p, sizeof(family)); - family = ntohl(family); - switch (family) { - case AF_INET: - gg_log_tmp("loop family AF_INET"); - ip = (struct ip *)(p + NULL_HDRLEN); - ip_handle(ip, pend, len); - break; - case AF_LINK: - ep = (struct ether_header *)((u_char *)p + NULL_HDRLEN); - ether_handle(ep, pend, len); - break; - default: - gg_log_tmp("unknown family %x !", family); - break; - } + struct ip *ip; + struct ether_header *ep; + u_int family; + const u_char *pend; + u_int len; + + gg_log_debug("user: pcap handler loop !"); + + /* XXX here i assume that packets are alligned, which might not + * be the case when using dump files, says tcpdump sources */ + + pend = p + h->caplen; + len = h->len - NULL_HDRLEN; + + memcpy((char *)&family, (char *)p, sizeof(family)); + family = ntohl(family); + switch (family) { + case AF_INET: + gg_log_tmp("loop family AF_INET"); + ip = (struct ip *)(p + NULL_HDRLEN); + ip_handle(ip, pend, len); + break; + case AF_LINK: + ep = (struct ether_header *)((u_char *)p + NULL_HDRLEN); + ether_handle(ep, pend, len); + break; + default: + gg_log_tmp("unknown family %x !", family); + break; + } } #endif /* __OpenBSD__ */ -- cgit v1.2.3-59-g8ed1b From da53472f1edb335eb0e234afdc0fb029046c16f3 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 10 Mar 2013 14:52:21 +0100 Subject: egraph: simplify pkg-config call from vtorri --- egraph/Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/egraph/Makefile b/egraph/Makefile index 3aa6042..99e8310 100644 --- a/egraph/Makefile +++ b/egraph/Makefile @@ -1,8 +1,6 @@ # CFLAGS += -Werror -Wall -O2 -fPIC -shared -g CFLAGS += -Werror -Wall -fPIC -shared -g -CFLAGS += $(shell pkg-config --libs --cflags edje) -CFLAGS += $(shell pkg-config --libs --cflags efx) -CFLAGS += $(shell pkg-config --libs --cflags igraph) +CFLAGS += $(shell pkg-config --libs --cflags edje efx igraph) PREFIX=/usr/local INCLUDEDIR=$(PREFIX)/include -- cgit v1.2.3-59-g8ed1b From 2b803073028f5e2ce60f76f67d901358ef1e6696 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 10 Mar 2013 15:53:16 +0100 Subject: typo --- egraph/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/egraph/README b/egraph/README index dc4be18..4f15401 100644 --- a/egraph/README +++ b/egraph/README @@ -1,4 +1,4 @@ -egraph - library for rendring dynamic graphs in evas +egraph - library for rendering dynamic graphs in evas Requirements ============ -- cgit v1.2.3-59-g8ed1b From 3b6e234b47997a24584e82e70974e7d441762e52 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 10 Mar 2013 16:25:31 +0100 Subject: glougloud: missing usage \n --- glougloud/glougloud.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glougloud/glougloud.c b/glougloud/glougloud.c index 4c08dec..47f791b 100644 --- a/glougloud/glougloud.c +++ b/glougloud/glougloud.c @@ -37,7 +37,7 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-vi]", __progname); + fprintf(stderr, "usage: %s [-vi]\n", __progname); exit(1); } -- cgit v1.2.3-59-g8ed1b From 847a4483015f88690cb631dcead7848fad6e3649 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 10 Mar 2013 16:25:49 +0100 Subject: glougloud: fix usage() wrong option --- glougloud/glougloud.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glougloud/glougloud.c b/glougloud/glougloud.c index 47f791b..2a87492 100644 --- a/glougloud/glougloud.c +++ b/glougloud/glougloud.c @@ -37,7 +37,7 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-vi]\n", __progname); + fprintf(stderr, "usage: %s [-hi]\n", __progname); exit(1); } -- cgit v1.2.3-59-g8ed1b From 8aaed78b8be64fd093b276eeffe645cceb48d951 Mon Sep 17 00:00:00 2001 From: Laurent Ghigonis Date: Sun, 10 Mar 2013 16:28:13 +0100 Subject: gg_sniff: fix missing usage() \n --- gg_sniff/gg_sniff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gg_sniff/gg_sniff.c b/gg_sniff/gg_sniff.c index 656c38c..cd2d2c5 100644 --- a/gg_sniff/gg_sniff.c +++ b/gg_sniff/gg_sniff.c @@ -39,7 +39,7 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-hv] [-i interface] [ip [port]]", __progname); + fprintf(stderr, "usage: %s [-hv] [-i interface] [ip [port]]\n", __progname); exit(1); } -- cgit v1.2.3-59-g8ed1b