-
Notifications
You must be signed in to change notification settings - Fork 0
/
evas.js
125 lines (105 loc) · 2.29 KB
/
evas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
var EVAS_OBJECT_RECTANGLE = 0;
var EVAS_OBJECT_BOX = 1;
var evasses = new Array();
/* functions to create and handle evas */
function _evas_new(w, h)
{
this.evas_objects = new Array();
this.ts = new Date().getTime();
this.id = "Evas" + this.ts;
if (!w)
var w = 0;
if (!h)
var h = 0;
this.w = w;
this.h = h;
return this;
}
function evas_new(w, h)
{
var e = new _evas_new(w, h);
console.log("Addinng evas %s", evas_id_get(e));
evasses.push(e);
return e;
}
function evas_id_get(evas)
{
return evas.id;
}
function evas_size_get(o)
{
return {w : o.w, h : o.h};
}
function evas_object_append(evas, evas_object)
{
console.log("Appending %d to array with for now %d elements", evas_object.type, evas_objects_get(evas).length);
evas_objects_get(evas).push(evas_object);
}
function evas_object_del(evas, o)
{
var a = evas_objects_get(evas);
for (var i = 0; i < a.length; i++)
{
if (a[i] == o)
a.splice(i,1);
}
}
function evas_objects_get(evas)
{
return evas.evas_objects;
}
function evas_draw_defaults_set(ctxt, o)
{
// Nothing do do here yet
}
function evas_draw(evas)
{
console.log("evas with %d elements is drawn", evas_objects_get(evas).length);
var e = document.createElement('canvas');
e.setAttribute('id', evas.id);
document.body.appendChild(e);
var es = evas_size_get(evas);
e.width = es.w;
e.height = es.h;
var ctx = e.getContext("2d");
for (var i = 0; i < evas_objects_get(evas).length; i++)
{
var o = evas_objects_get(evas)[i];
if (!evas_object_visible_get(o))
continue;
evas_draw_defaults_set(ctx, o);
switch (o.type)
{
case EVAS_OBJECT_RECTANGLE:
evas_draw_evas_object_rectangle(ctx, o);
break;
default:
break;
}
}
}
function evas_del(evas)
{
var e = document.getElementById(evas_id_get(evas));
if (!e) return;
var p = e.parentNode;
p.removeChild(e);
}
function evasses_del()
{
var e;
for (var i = (evasses.length - 1); i >= 0, e = evasses[i]; i--)
{
console.log("deleting evas %s", evas_id_get(e));
evas_del(e);
evasses.pop();
}
}
function evas_draw_evas_object_rectangle(ctx, o)
{
//set style according to attribute values
var geo = evas_object_geometry_get(o);
ctx.fillStyle = evas_object_rectangle_color_get(o);
ctx.fillRect(geo.x, geo.y, geo.w, geo.h);
//console.log("o geometry: %d %d %d %d", geo.x ,geo.y, geo.w, geo.h);
}