forked from aruanruan/OpenTopo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scene.js
84 lines (66 loc) · 1.97 KB
/
Scene.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
var Scene = Base.extend({
fillStyle:"green",//背景
scaleX:1,//横向缩放角度
scaleY:1,//纵向缩放角度
translateX:0,//横向偏移
translateY:0,//纵向偏移
wheelZoom:0.95,//鼠标缩放速度
dragEnable:true,//鼠标是否可以拖拽更改偏移量
text:null,
init:function(stage){
if(stage){
stage.curScene = this;
}
this._elements = [];
},
paint:function(ctx){
var canvas = ctx.canvas;
ctx.save();
//#region 设置背景
ctx.save();
ctx.fillStyle = this.fillStyle;
ctx.fillRect(0,0,canvas.width,canvas.height);
ctx.restore();
//#endregion
if(this.text) {
ctx.save();
ctx.textBaseline = "top";
ctx.font = "15px Arial";
ctx.fillText(this.text, 10, 10);
ctx.restore();
}
//位移
ctx.translate(this.translateX,this.translateY);
//#region 中心缩放
ctx.translate(canvas.width/2-this.translateX,canvas.height/2-this.translateY);
ctx.scale(this.scaleX,this.scaleY);
ctx.translate(-canvas.width/2+this.translateX,-canvas.height/2+this.translateY);
//#endregion
for(var i=0;i<this._elements.length;i++){
var ele = this._elements[i];
ele.paint(ctx);
//鼠标焦点
if(ele == this.focus){
ele.paintFocus(ctx);
}
//气泡
if(ele.tooltipText && (ele==this.focus || ele.tooltipAlway)){
ele.paintTooltip(ctx);
}
//被选择
if(ele.selected){
ele.paintSelected(ctx);
}
}
ctx.restore();
},
//ele...
add:function(){
for(var i in arguments){
this._elements.push(arguments[i]);
}
this._elements.sort(function(a,b){
return a.z_index-b.z_index;
})
}
});