busy adding some MEAT to edje's embryo script support. just added
"persistent" variables - ie tied to each instance of an edje object and you can save/load via get_int() set_int() get_float() set_float(), get_str(), get_strlen() and set_str(). the values are fetched/stored wherever you do these calls. you need a public variable declaration to indicate you want to use a global var, and use this variable handle as the variable index - edje will init it for you. e_logo.edc has some examples... :) this solves being able to keep state like if a check button is enabled or disabled etc. etc. etc. then i guess its onto the rest of the calls... SVN revision: 9526
This commit is contained in:
parent
14ab26edd4
commit
7bd60e9cb0
|
@ -1,3 +1,12 @@
|
|||
native tst();
|
||||
native emit(sig[], src[]);
|
||||
|
||||
/* edje exported calls */
|
||||
native get_int (id);
|
||||
native set_int (id, val);
|
||||
native Float:get_float (id);
|
||||
native set_float (id, Float:val);
|
||||
native get_strlen(id);
|
||||
native get_str (id, dst[], maxlen);
|
||||
native set_str (id, str[]);
|
||||
|
||||
native tst();
|
||||
native emit(sig[], src[]);
|
||||
|
||||
|
|
|
@ -143,6 +143,11 @@ collections {
|
|||
item: "My Data" "The string to attach to this data";
|
||||
item: "The Key" "String data attached to the key";
|
||||
}
|
||||
script {
|
||||
public global_int;
|
||||
public global_float;
|
||||
public global_str;
|
||||
}
|
||||
parts {
|
||||
part {
|
||||
name: "background";
|
||||
|
@ -468,6 +473,25 @@ collections {
|
|||
// action: SIGNAL_EMIT "do_it" "the_source";
|
||||
script {
|
||||
emit("PROGRAAAAAAAM", "TEEEEEEEEEEEEEST");
|
||||
set_int(global_int, 10);
|
||||
set_float(global_float, 10.0);
|
||||
set_str(global_str, "smelly fish");
|
||||
new buf[256];
|
||||
|
||||
new i;
|
||||
i = get_int(global_int);
|
||||
snprintf(buf, 256, "1. i = %i :)", i);
|
||||
emit("DEBUG...", buf);
|
||||
|
||||
new Float:f;
|
||||
f = get_float(global_float);
|
||||
snprintf(buf, 256, "2. f = %f :)", f);
|
||||
emit("DEBUG...", buf);
|
||||
|
||||
new s[256];
|
||||
get_str(global_str, s, 256);
|
||||
snprintf(buf, 256, "3. s = %s :)", s);
|
||||
emit("DEBUG...", buf);
|
||||
}
|
||||
}
|
||||
program {
|
||||
|
|
|
@ -445,7 +445,15 @@ data_write(void)
|
|||
snprintf(buf, sizeof(buf), "embryo_cc -i%s -o%s %s",
|
||||
DAT"data/include", tmpo, tmpn);
|
||||
ret = system(buf);
|
||||
printf("ret = %i\n", ret);
|
||||
/*
|
||||
if (ret != 0)
|
||||
{
|
||||
printf("%i\n", ret);
|
||||
fprintf(stderr, "%s: Warning. Compiling script code not clean.\n",
|
||||
progname);
|
||||
ABORT_WRITE(ef, file_out);
|
||||
}
|
||||
*/
|
||||
close(fd);
|
||||
}
|
||||
f = fopen(tmpo, "r");
|
||||
|
|
|
@ -123,6 +123,13 @@ Edje_Edit_Image *edje_edit_iamge_get_by_id(int id);
|
|||
#define EDJE_TWEEN_MODE_DECELERATE 4
|
||||
#define EDJE_TWEEN_MODE_LAST 5
|
||||
|
||||
#define EDJE_VAR_NONE 0
|
||||
#define EDJE_VAR_INT 1
|
||||
#define EDJE_VAR_FLOAT 2
|
||||
#define EDJE_VAR_STRING 3
|
||||
|
||||
#define EDJE_VAR_MAGIC_BASE 0x12fe84ba
|
||||
|
||||
/*----------*/
|
||||
|
||||
struct _Edje_File
|
||||
|
@ -371,6 +378,11 @@ typedef struct _Edje_Pending_Program Edje_Pending_Program;
|
|||
typedef struct _Edje_Text_Style Edje_Text_Style;
|
||||
typedef struct _Edje_Color_Class Edje_Color_Class;
|
||||
typedef struct _Edje_Text_Class Edje_Text_Class;
|
||||
typedef struct _Edje_Var Edje_Var;
|
||||
typedef struct _Edje_Var_Int Edje_Var_Int;
|
||||
typedef struct _Edje_Var_Float Edje_Var_Float;
|
||||
typedef struct _Edje_Var_String Edje_Var_String;
|
||||
typedef struct _Edje_Var_Pool Edje_Var_Pool;
|
||||
|
||||
struct _Edje
|
||||
{
|
||||
|
@ -412,6 +424,7 @@ struct _Edje
|
|||
Evas_List *emissions;
|
||||
int load_error;
|
||||
int freeze;
|
||||
Edje_Var_Pool *var_pool;
|
||||
};
|
||||
|
||||
struct _Edje_Real_Part
|
||||
|
@ -567,6 +580,37 @@ struct _Edje_Text_Class
|
|||
double size;
|
||||
};
|
||||
|
||||
struct _Edje_Var_Int
|
||||
{
|
||||
int v;
|
||||
};
|
||||
|
||||
struct _Edje_Var_Float
|
||||
{
|
||||
double v;
|
||||
};
|
||||
|
||||
struct _Edje_Var_String
|
||||
{
|
||||
char *v;
|
||||
};
|
||||
|
||||
struct _Edje_Var_Pool
|
||||
{
|
||||
int size;
|
||||
Edje_Var *vars;
|
||||
};
|
||||
|
||||
struct _Edje_Var
|
||||
{
|
||||
unsigned char type;
|
||||
union {
|
||||
Edje_Var_Int i;
|
||||
Edje_Var_Float f;
|
||||
Edje_Var_String s;
|
||||
} data;
|
||||
};
|
||||
|
||||
void _edje_part_pos_set(Edje *ed, Edje_Real_Part *ep, int mode, double pos);
|
||||
void _edje_part_description_apply(Edje *ed, Edje_Real_Part *ep, char *d1, double v1, char *d2, double v2);
|
||||
void _edje_recalc(Edje *ed);
|
||||
|
|
|
@ -34,6 +34,7 @@ edje_program.c \
|
|||
edje_smart.c \
|
||||
edje_text.c \
|
||||
edje_util.c \
|
||||
edje_var.c \
|
||||
edje_private.h
|
||||
|
||||
libedje_la_LIBADD = $(LDFLAGS) -lm @evas_libs@ @ecore_libs@ @eet_libs@ @embryo_libs@
|
||||
|
|
|
@ -1,50 +1,8 @@
|
|||
#include "Edje.h"
|
||||
#include "edje_private.h"
|
||||
|
||||
#define CHKPARAM(n) if (params[0] != (sizeof(Embryo_Cell) * (n))) return 0;
|
||||
|
||||
/**** All the api exported to edje scripts ****/
|
||||
/* tst() */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_tst(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
|
||||
/* params[0] = number of bytes of params passed */
|
||||
ed = embryo_program_data_get(ep);
|
||||
printf("EDJE DEBUG: Embryo code detected for \"%s\":\"%s\"\n",
|
||||
ed->path, ed->part);
|
||||
return 7;
|
||||
}
|
||||
|
||||
/* emit(sig[], src[]) */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_emit(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
Embryo_Cell *cptr;
|
||||
char *sig, *src;
|
||||
int l;
|
||||
|
||||
CHKPARAM(2);
|
||||
ed = embryo_program_data_get(ep);
|
||||
|
||||
cptr = embryo_data_address_get(ep, params[1]);
|
||||
l = embryo_data_string_length_get(ep, cptr);
|
||||
sig = alloca(l + 1);
|
||||
embryo_data_string_get(ep, cptr, sig);
|
||||
|
||||
cptr = embryo_data_address_get(ep, params[2]);
|
||||
l = embryo_data_string_length_get(ep, cptr);
|
||||
src = alloca(l + 1);
|
||||
embryo_data_string_get(ep, cptr, src);
|
||||
|
||||
_edje_emit(ed, sig, src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* ALREADY EXPORTEd By EMBRYO:
|
||||
* ALREADY EXPORTED BY EMBRYO:
|
||||
*
|
||||
* Float:atof(string[]);
|
||||
* Float:fract(Float:value);
|
||||
|
@ -73,29 +31,168 @@ _edje_embryo_fn_emit(Embryo_Program *ep, Embryo_Cell *params)
|
|||
* strchr(str[], ch[]);
|
||||
* strrchr(str[], ch[]);
|
||||
* rand();
|
||||
*
|
||||
* ROUTINES TO EXPORT:
|
||||
*
|
||||
* BASIC NUTS & BOLTS
|
||||
*/
|
||||
|
||||
#define CHKPARAM(n) if (params[0] != (sizeof(Embryo_Cell) * (n))) return 0;
|
||||
#define GETSTR(str, par) { \
|
||||
Embryo_Cell *___cptr; \
|
||||
int ___l; \
|
||||
if ((___cptr = embryo_data_address_get(ep, (par)))) { \
|
||||
___l = embryo_data_string_length_get(ep, ___cptr); \
|
||||
if (((str) = alloca(___l + 1))) \
|
||||
embryo_data_string_get(ep, ___cptr, (str));}}
|
||||
#define SETSTR(str, par) { \
|
||||
Embryo_Cell *___cptr; \
|
||||
if ((___cptr = embryo_data_address_get(ep, (par)))) { \
|
||||
embryo_data_string_set(ep, str, ___cptr);}}
|
||||
|
||||
static void _edje_embryo_globals_init(Edje *ed);
|
||||
|
||||
/* BASIC NUTS & BOLTS
|
||||
*
|
||||
* get_int(key[])
|
||||
* set_int(key[], val)
|
||||
* get_float(key[])
|
||||
* set_float(key[], Float:val)
|
||||
* get_strlen(key[])
|
||||
* get_str(key[], dst[], maxlen)
|
||||
* set_str(key[], str[])
|
||||
*
|
||||
* TIMERS... (tick off in N seconds from now)
|
||||
*/
|
||||
|
||||
/* get_int(id) */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_get_int(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
|
||||
CHKPARAM(1);
|
||||
ed = embryo_program_data_get(ep);
|
||||
return (Embryo_Cell)_edje_var_int_get(ed, (int)params[1]);
|
||||
}
|
||||
|
||||
/* set_int(id, v) */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_set_int(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
|
||||
CHKPARAM(2);
|
||||
ed = embryo_program_data_get(ep);
|
||||
_edje_var_int_set(ed, (int)params[1], (int)params[2]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get_float(id) */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_get_float(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
float v;
|
||||
|
||||
CHKPARAM(1);
|
||||
ed = embryo_program_data_get(ep);
|
||||
v = (float)_edje_var_float_get(ed, params[1]);
|
||||
return EMBRYO_FLOAT_TO_CELL(v);
|
||||
}
|
||||
|
||||
/* set_float(id, v) */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_set_float(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
float v;
|
||||
|
||||
CHKPARAM(2);
|
||||
ed = embryo_program_data_get(ep);
|
||||
v = EMBRYO_CELL_TO_FLOAT(params[2]);
|
||||
_edje_var_float_set(ed, (int)params[1], (double)v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get_str(id, dst[], maxlen) */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_get_str(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
char *s;
|
||||
|
||||
CHKPARAM(3);
|
||||
if (params[3] < 1) return 0;
|
||||
ed = embryo_program_data_get(ep);
|
||||
s = (char *)_edje_var_str_get(ed, (int)params[1]);
|
||||
if (s)
|
||||
{
|
||||
if (strlen(s) < params[3])
|
||||
{
|
||||
SETSTR(s, params[2]);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *ss;
|
||||
|
||||
ss = strdup(s);
|
||||
if (ss)
|
||||
{
|
||||
ss[params[3] - 1] = 0;
|
||||
SETSTR(ss, params[2]);
|
||||
free(ss);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SETSTR("", params[2]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get_strlen(id) */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_get_strlen(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
char *s;
|
||||
|
||||
CHKPARAM(1);
|
||||
ed = embryo_program_data_get(ep);
|
||||
s = (char *)_edje_var_str_get(ed, (int)params[1]);
|
||||
if (s)
|
||||
{
|
||||
return strlen(s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* set_str(id, str[]) */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_set_str(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
char *s;
|
||||
|
||||
CHKPARAM(2);
|
||||
ed = embryo_program_data_get(ep);
|
||||
GETSTR(s, params[2]);
|
||||
if (s)
|
||||
{
|
||||
_edje_var_str_set(ed, (int)params[1], s);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* TIMERS... (tick off in N seconds from now)
|
||||
*
|
||||
* timer(Float:in, fname[], val)
|
||||
* cancel_timer(id)
|
||||
*
|
||||
* ANIMATORS... (run for N seconds, passing in position)
|
||||
*/
|
||||
|
||||
/* ANIMATORS... (run for N seconds, passing in position)
|
||||
*
|
||||
* anim(Float:length, fname[], ...) (varargs = series of int's - no strings))
|
||||
* candel_anim(id);
|
||||
*
|
||||
* EDJE...
|
||||
* cancel_anim(id);
|
||||
*/
|
||||
|
||||
/* EDJE...
|
||||
*
|
||||
* set_state(part[], state[], Float:state_val)
|
||||
* set_tween_state(part[], state1[], Float:state1_val, state2[], Float:state2_val)
|
||||
|
@ -135,13 +232,14 @@ _edje_embryo_fn_emit(Embryo_Program *ep, Embryo_Cell *params)
|
|||
* get_repeat_events(name[])
|
||||
* set_clip(name[], clip_name[])
|
||||
* get_clip(name[], clip_name_dst[], clip_name_dst_max)
|
||||
*
|
||||
* MODIFY STATE VALUES
|
||||
*/
|
||||
|
||||
/* MODIFY STATE VALUES
|
||||
*
|
||||
* set_state_val(name[], state[], Float:state_val, Param:param, ...)
|
||||
* get_state_val(name[], state[], Float:state_val, Param:param, ...)
|
||||
*
|
||||
* for these:
|
||||
* FOR THESE PROPERTIES:
|
||||
*
|
||||
* visible
|
||||
* align[x,y]
|
||||
|
@ -169,26 +267,65 @@ _edje_embryo_fn_emit(Embryo_Program *ep, Embryo_Cell *params)
|
|||
* text[fit_x,fit_y]
|
||||
* text[min_x,min_y]
|
||||
* text[align_x,align_y]
|
||||
*
|
||||
* FUTURE: KEYS???
|
||||
*/
|
||||
|
||||
/* FUTURE: KEYS???
|
||||
*
|
||||
*/
|
||||
|
||||
/**** All the api exported to edje scripts ****/
|
||||
/* tst() */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_tst(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
|
||||
/* params[0] = number of bytes of params passed */
|
||||
ed = embryo_program_data_get(ep);
|
||||
printf("EDJE DEBUG: Embryo code detected for \"%s\":\"%s\"\n",
|
||||
ed->path, ed->part);
|
||||
return 7;
|
||||
}
|
||||
|
||||
/* emit(sig[], src[]) */
|
||||
static Embryo_Cell
|
||||
_edje_embryo_fn_emit(Embryo_Program *ep, Embryo_Cell *params)
|
||||
{
|
||||
Edje *ed;
|
||||
char *sig, *src;
|
||||
|
||||
CHKPARAM(2);
|
||||
ed = embryo_program_data_get(ep);
|
||||
GETSTR(sig, params[1]);
|
||||
GETSTR(src, params[2]);
|
||||
if ((!sig) || (!src)) return 0;
|
||||
_edje_emit(ed, sig, src);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
_edje_embryo_script_init(Edje *ed)
|
||||
{
|
||||
Embryo_Program *ep;
|
||||
|
||||
|
||||
if (!ed) return;
|
||||
if (!ed->collection) return;
|
||||
if (!ed->collection->script) return;
|
||||
ep = ed->collection->script;
|
||||
embryo_program_data_set(ep, ed);
|
||||
/* first advertise all the edje "script" calls */
|
||||
embryo_program_native_call_add(ep, "get_int", _edje_embryo_fn_get_int);
|
||||
embryo_program_native_call_add(ep, "set_int", _edje_embryo_fn_set_int);
|
||||
embryo_program_native_call_add(ep, "get_float", _edje_embryo_fn_get_float);
|
||||
embryo_program_native_call_add(ep, "set_float", _edje_embryo_fn_set_float);
|
||||
embryo_program_native_call_add(ep, "get_str", _edje_embryo_fn_get_str);
|
||||
embryo_program_native_call_add(ep, "get_strlen", _edje_embryo_fn_get_strlen);
|
||||
embryo_program_native_call_add(ep, "set_str", _edje_embryo_fn_set_str);
|
||||
|
||||
embryo_program_native_call_add(ep, "tst", _edje_embryo_fn_tst);
|
||||
embryo_program_native_call_add(ep, "emit", _edje_embryo_fn_emit);
|
||||
|
||||
embryo_program_vm_push(ep); /* neew a new vm to run in */
|
||||
_edje_embryo_globals_init(ed);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -211,6 +348,7 @@ _edje_embryo_script_reset(Edje *ed)
|
|||
if (!ed->collection->script) return;
|
||||
if (embryo_program_recursion_get(ed->collection->script) > 0) return;
|
||||
embryo_program_vm_reset(ed->collection->script);
|
||||
_edje_embryo_globals_init(ed);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -232,3 +370,24 @@ _edje_embryo_test_run(Edje *ed, char *fname, char *sig, char *src)
|
|||
printf("EDJE DEBUG: Done.\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
_edje_embryo_globals_init(Edje *ed)
|
||||
{
|
||||
int n, i;
|
||||
Embryo_Program *ep;
|
||||
|
||||
ep = ed->collection->script;
|
||||
n = embryo_program_variable_count_get(ep);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
Embryo_Cell cell, *cptr;
|
||||
|
||||
cell = embryo_program_variable_get(ep, i);
|
||||
if (cell != EMBRYO_CELL_NONE)
|
||||
{
|
||||
cptr = embryo_data_address_get(ep, cell);
|
||||
if (cptr) *cptr = EDJE_VAR_MAGIC_BASE + i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,6 +187,7 @@ edje_object_file_set(Evas_Object *obj, const char *file, const char *part)
|
|||
_edje_block(ed);
|
||||
_edje_freeze(ed);
|
||||
if (ed->collection->script) _edje_embryo_script_init(ed);
|
||||
_edje_var_init(ed);
|
||||
_edje_emit(ed, "load", "");
|
||||
for (l = ed->parts; l; l = l->next)
|
||||
{
|
||||
|
@ -451,6 +452,7 @@ _edje_file_del(Edje *ed)
|
|||
_edje_emit(ed, NULL, NULL); /* clear out signal emissions */
|
||||
ed->dont_clear_signals = 1;
|
||||
_edje_block_violate(ed);
|
||||
_edje_var_shutdown(ed);
|
||||
if (ed->collection)
|
||||
{
|
||||
ed->collection->references--;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include <math.h>
|
||||
#include <fnmatch.h>
|
||||
#include <alloca.h>
|
||||
|
||||
#include "Edje_Edit.h"
|
||||
|
||||
|
@ -56,9 +57,18 @@ extern Evas_List *_edje_animators;
|
|||
extern Edje_Text_Style _edje_text_styles[EDJE_TEXT_EFFECT_LAST];
|
||||
extern Evas_List *_edje_edjes;
|
||||
|
||||
void _edje_embryo_script_init (Edje *ed);
|
||||
void _edje_embryo_script_shutdown (Edje *ed);
|
||||
void _edje_embryo_script_reset (Edje *ed);
|
||||
void _edje_embryo_test_run (Edje *ed, char *fname, char *sig, char *src);
|
||||
|
||||
void _edje_embryo_script_init (Edje *ed);
|
||||
void _edje_embryo_script_shutdown (Edje *ed);
|
||||
void _edje_embryo_script_reset (Edje *ed);
|
||||
void _edje_embryo_test_run (Edje *ed, char *fname, char *sig, char *src);
|
||||
void _edje_var_init (Edje *ed);
|
||||
void _edje_var_shutdown (Edje *ed);
|
||||
int _edje_var_string_id_get (Edje *ed, char *string);
|
||||
int _edje_var_int_get (Edje *ed, int id);
|
||||
void _edje_var_int_set (Edje *ed, int id, int v);
|
||||
double _edje_var_float_get (Edje *ed, int id);
|
||||
void _edje_var_float_set (Edje *ed, int id, double v);
|
||||
const char *_edje_var_str_get (Edje *ed, int id);
|
||||
void _edje_var_str_set (Edje *ed, int id, char *str);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -995,6 +995,10 @@ edje_object_part_drag_page(Evas_Object *obj, const char *part, double dx, double
|
|||
_edje_emit(ed, "drag,page", rp->part->name);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Edje_Real_Part *
|
||||
_edje_real_part_get(Edje *ed, char *part)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,250 @@
|
|||
#include "Edje.h"
|
||||
#include "edje_private.h"
|
||||
|
||||
void
|
||||
_edje_var_init(Edje *ed)
|
||||
{
|
||||
if (!ed) return;
|
||||
if (!ed->collection) return;
|
||||
if (!ed->collection->script) return;
|
||||
ed->var_pool = calloc(1, sizeof(Edje_Var_Pool));
|
||||
if (!ed->var_pool) return;
|
||||
ed->var_pool->size = embryo_program_variable_count_get(ed->collection->script);
|
||||
ed->var_pool->vars = calloc(1, sizeof(Edje_Var) * ed->var_pool->size);
|
||||
}
|
||||
|
||||
void
|
||||
_edje_var_shutdown(Edje *ed)
|
||||
{
|
||||
if (!ed->var_pool) return;
|
||||
if (ed->var_pool->vars)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ed->var_pool->size; i++)
|
||||
{
|
||||
if (ed->var_pool->vars[i].type == EDJE_VAR_STRING)
|
||||
{
|
||||
if (ed->var_pool->vars[i].data.s.v)
|
||||
{
|
||||
free(ed->var_pool->vars[i].data.s.v);
|
||||
ed->var_pool->vars[i].data.s.v = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
free(ed->var_pool->vars);
|
||||
}
|
||||
free(ed->var_pool);
|
||||
ed->var_pool = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
_edje_var_string_id_get(Edje *ed, char *string)
|
||||
{
|
||||
Embryo_Cell cell, *cptr;
|
||||
|
||||
if (!ed) return 0;
|
||||
if (!ed->collection) return 0;
|
||||
if (!ed->collection->script) return 0;
|
||||
if (!string) return;
|
||||
cell = embryo_program_variable_find(ed->collection->script, string);
|
||||
if (cell == EMBRYO_CELL_NONE) return 0;
|
||||
cptr = embryo_data_address_get(ed->collection->script, cell);
|
||||
if (!cptr) return 0;
|
||||
return (int)(*cptr);
|
||||
}
|
||||
|
||||
int
|
||||
_edje_var_int_get(Edje *ed, int id)
|
||||
{
|
||||
if (!ed) return 0;
|
||||
if (!ed->var_pool) return 0;
|
||||
id -= EDJE_VAR_MAGIC_BASE;
|
||||
if ((id < 0) || (id >= ed->var_pool->size)) return 0;
|
||||
/* auto-cast */
|
||||
if (ed->var_pool->vars[id].type == EDJE_VAR_STRING)
|
||||
{
|
||||
if (ed->var_pool->vars[id].data.s.v)
|
||||
{
|
||||
double f;
|
||||
|
||||
f = atof(ed->var_pool->vars[id].data.s.v);
|
||||
free(ed->var_pool->vars[id].data.s.v);
|
||||
ed->var_pool->vars[id].data.s.v = NULL;
|
||||
ed->var_pool->vars[id].data.i.v = (int)f;
|
||||
}
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_INT;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_FLOAT)
|
||||
{
|
||||
int v;
|
||||
|
||||
v = (int)(ed->var_pool->vars[id].data.f.v);
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_INT;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
|
||||
{
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_INT;
|
||||
}
|
||||
return ed->var_pool->vars[id].data.i.v;
|
||||
}
|
||||
|
||||
void
|
||||
_edje_var_int_set(Edje *ed, int id, int v)
|
||||
{
|
||||
if (!ed) return;
|
||||
if (!ed->var_pool) return;
|
||||
id -= EDJE_VAR_MAGIC_BASE;
|
||||
if ((id < 0) || (id >= ed->var_pool->size)) return;
|
||||
/* auto-cast */
|
||||
if (ed->var_pool->vars[id].type == EDJE_VAR_STRING)
|
||||
{
|
||||
if (ed->var_pool->vars[id].data.s.v)
|
||||
{
|
||||
free(ed->var_pool->vars[id].data.s.v);
|
||||
ed->var_pool->vars[id].data.s.v = NULL;
|
||||
}
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_INT;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_FLOAT)
|
||||
{
|
||||
ed->var_pool->vars[id].data.f.v = 0;
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_INT;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
|
||||
{
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_INT;
|
||||
}
|
||||
ed->var_pool->vars[id].data.i.v = v;
|
||||
}
|
||||
|
||||
double
|
||||
_edje_var_float_get(Edje *ed, int id)
|
||||
{
|
||||
if (!ed) return 0;
|
||||
if (!ed->var_pool) return 0;
|
||||
id -= EDJE_VAR_MAGIC_BASE;
|
||||
if ((id < 0) || (id >= ed->var_pool->size)) return 0;
|
||||
/* auto-cast */
|
||||
if (ed->var_pool->vars[id].type == EDJE_VAR_STRING)
|
||||
{
|
||||
if (ed->var_pool->vars[id].data.s.v)
|
||||
{
|
||||
double f;
|
||||
|
||||
f = atof(ed->var_pool->vars[id].data.s.v);
|
||||
free(ed->var_pool->vars[id].data.s.v);
|
||||
ed->var_pool->vars[id].data.s.v = NULL;
|
||||
ed->var_pool->vars[id].data.f.v = f;
|
||||
}
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_FLOAT;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_INT)
|
||||
{
|
||||
int v;
|
||||
|
||||
v = (int)(ed->var_pool->vars[id].data.f.v);
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_FLOAT;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
|
||||
{
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_FLOAT;
|
||||
}
|
||||
return ed->var_pool->vars[id].data.f.v;
|
||||
}
|
||||
|
||||
void
|
||||
_edje_var_float_set(Edje *ed, int id, double v)
|
||||
{
|
||||
if (!ed) return;
|
||||
if (!ed->var_pool) return;
|
||||
id -= EDJE_VAR_MAGIC_BASE;
|
||||
if ((id < 0) || (id >= ed->var_pool->size)) return;
|
||||
/* auto-cast */
|
||||
if (ed->var_pool->vars[id].type == EDJE_VAR_STRING)
|
||||
{
|
||||
if (ed->var_pool->vars[id].data.s.v)
|
||||
{
|
||||
free(ed->var_pool->vars[id].data.s.v);
|
||||
ed->var_pool->vars[id].data.s.v = NULL;
|
||||
}
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_FLOAT;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_INT)
|
||||
{
|
||||
ed->var_pool->vars[id].data.f.v = 0;
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_FLOAT;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
|
||||
{
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_FLOAT;
|
||||
}
|
||||
ed->var_pool->vars[id].data.f.v = v;
|
||||
}
|
||||
|
||||
const char *
|
||||
_edje_var_str_get(Edje *ed, int id)
|
||||
{
|
||||
if (!ed) return NULL;
|
||||
if (!ed->var_pool) return NULL;
|
||||
id -= EDJE_VAR_MAGIC_BASE;
|
||||
if ((id < 0) || (id >= ed->var_pool->size)) return NULL;
|
||||
/* auto-cast */
|
||||
if (ed->var_pool->vars[id].type == EDJE_VAR_INT)
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
snprintf(buf, sizeof(buf), "%i", ed->var_pool->vars[id].data.i.v);
|
||||
ed->var_pool->vars[id].data.s.v = strdup(buf);
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_STRING;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_FLOAT)
|
||||
{
|
||||
char buf[64];
|
||||
|
||||
snprintf(buf, sizeof(buf), "%f", ed->var_pool->vars[id].data.f.v);
|
||||
ed->var_pool->vars[id].data.s.v = strdup(buf);
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_STRING;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
|
||||
{
|
||||
ed->var_pool->vars[id].data.s.v = strdup("");
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_STRING;
|
||||
}
|
||||
return ed->var_pool->vars[id].data.s.v;
|
||||
}
|
||||
|
||||
void
|
||||
_edje_var_str_set(Edje *ed, int id, char *str)
|
||||
{
|
||||
if (!ed) return;
|
||||
if (!ed->var_pool) return;
|
||||
if (!str) return;
|
||||
id -= EDJE_VAR_MAGIC_BASE;
|
||||
if ((id < 0) || (id >= ed->var_pool->size)) return;
|
||||
/* auto-cast */
|
||||
if (ed->var_pool->vars[id].type == EDJE_VAR_STRING)
|
||||
{
|
||||
if (ed->var_pool->vars[id].data.s.v)
|
||||
{
|
||||
free(ed->var_pool->vars[id].data.s.v);
|
||||
ed->var_pool->vars[id].data.s.v = NULL;
|
||||
}
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_INT)
|
||||
{
|
||||
ed->var_pool->vars[id].data.f.v = 0;
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_STRING;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_FLOAT)
|
||||
{
|
||||
ed->var_pool->vars[id].data.f.v = 0;
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_STRING;
|
||||
}
|
||||
else if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
|
||||
{
|
||||
ed->var_pool->vars[id].type = EDJE_VAR_STRING;
|
||||
}
|
||||
ed->var_pool->vars[id].data.s.v = strdup(str);
|
||||
}
|
||||
|
Loading…
Reference in New Issue