trunk: changeset 1925
[notion/jeffpc.git] / ioncore / extlconv.c
blobf75064eecb9287f34c254cdc09b9dde3aa035be0
1 /*
2 * ion/ioncore/extlconv.c
4 * Copyright (c) Tuomo Valkonen 1999-2005.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
12 #include "common.h"
13 #include <libextl/extl.h>
14 #include "extlconv.h"
15 #include "region-iter.h"
18 /*{{{ Region list */
21 ExtlTab managed_list_to_table(WRegion *list, bool (*filter)(WRegion *r))
23 ExtlTab tab=extl_create_table();
24 int i=1;
25 WRegion *r;
27 FOR_ALL_MANAGED_ON_LIST(list, r){
28 if(filter==NULL || filter(r)){
29 extl_table_seti_o(tab, i, (Obj*)r);
30 i++;
34 return tab;
38 /*}}}*/
41 /*{{{ Booleans */
44 bool extl_table_is_bool_set(ExtlTab tab, const char *entry)
46 bool b;
48 if(extl_table_gets_b(tab, entry, &b))
49 return b;
50 return FALSE;
54 /*}}}*/
57 /*{{{ Rectangles */
60 bool extl_table_to_rectangle(ExtlTab tab, WRectangle *rectret)
62 if(!extl_table_gets_i(tab, "x", &(rectret->x)) ||
63 !extl_table_gets_i(tab, "y", &(rectret->y)) ||
64 !extl_table_gets_i(tab, "w", &(rectret->w)) ||
65 !extl_table_gets_i(tab, "h", &(rectret->h)))
66 return FALSE;
68 return TRUE;
72 ExtlTab extl_table_from_rectangle(const WRectangle *rect)
74 ExtlTab tab=extl_create_table();
76 extl_table_sets_i(tab, "x", rect->x);
77 extl_table_sets_i(tab, "y", rect->y);
78 extl_table_sets_i(tab, "w", rect->w);
79 extl_table_sets_i(tab, "h", rect->h);
81 return tab;
85 void extl_table_sets_rectangle(ExtlTab tab, const char *nam,
86 const WRectangle *rect)
88 ExtlTab g=extl_table_from_rectangle(rect);
89 extl_table_sets_t(tab, nam, g);
90 extl_unref_table(g);
94 bool extl_table_gets_rectangle(ExtlTab tab, const char *nam,
95 WRectangle *rect)
97 ExtlTab g;
98 bool ok;
100 if(!extl_table_gets_t(tab, nam, &g))
101 return FALSE;
103 ok=extl_table_to_rectangle(g, rect);
105 extl_unref_table(g);
107 return ok;
111 /*}}}*/