Subversion Repositories php-qbpwcf

Rev

Rev 3 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
226 liveuser 6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
3 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
27
類別說明:
28
提供2D、3D繪圖應用的類別.
29
備註:
30
無.
31
*/
32
class canvas{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	*/
47
	public function __call($method,$arguments){
48
 
49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
51
 
52
		#設置執行不正常
53
		$result["status"]="false";
54
 
55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
57
 
58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
60
 
61
		#回傳結果
62
		return $result;
63
 
64
		}#function __call end
65
 
66
	/*
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
71
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
72
	#$result["function"],當前執行的函式名稱.
73
	#必填參數:
74
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
79
	public static function __callStatic($method,$arguments){
80
 
81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
83
 
84
		#設置執行不正常
85
		$result["status"]="false";
86
 
87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
89
 
90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
92
 
93
		#回傳結果
94
		return $result;
95
 
96
		}#function __callStatic end
226 liveuser 97
 
3 liveuser 98
	/*
99
	#函式說明:
100
	#展示canvas
101
	#回傳的結果:
102
	#回傳結果:
103
	#無.
104
	#必填參數:
105
	#無.
106
	#可省略參數:
107
	#無.
108
	#參考資料:
109
	#無.
110
	#備註:
111
	#無.
112
	*/
113
	public static function demo(){
114
 
115
		#函式說明:
116
		#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
117
		#回傳結果:
118
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
119
		#$result["error"],錯誤訊息陣列
120
		#$result["function"],當前執行的函數名稱
121
		#$result["content"],要執行的javaScript語法
122
		#必填參數:
123
		#$conf["script"],字串,要執行的javaScript語法.
124
		$conf["javaScript::toScript"]["script"]=
125
		"
126
		//建立 canvas
127
		var canvas=document.createElement('canvas');
226 liveuser 128
 
3 liveuser 129
		//設置寬度為 100%
130
		canvas.style.width='100%';
226 liveuser 131
 
3 liveuser 132
		//設置高度為 100% - logo
133
		canvas.style.height='calc( 100% - 20px )';
226 liveuser 134
 
3 liveuser 135
		//放置 canvas
136
		document.body.prepend(canvas);
226 liveuser 137
 
3 liveuser 138
		//代表要使用2D環境
139
		var context2D=canvas.getContext('2d');
226 liveuser 140
 
3 liveuser 141
		//設置顏色為全黑
142
		context2D.fillStyle='#000000';
226 liveuser 143
 
3 liveuser 144
		//繪製矩形,寬為500px,高為300px
145
		context2D.fillRect(0,0,500,300);
226 liveuser 146
 
3 liveuser 147
		//設置白色
148
		context2D.fillStyle='#ffffff';
226 liveuser 149
 
3 liveuser 150
		//設置文字大小
151
		context2D.font='20px Sans-Serif';
226 liveuser 152
 
3 liveuser 153
		//設置對齊方式
154
		context2D.textBaseline='top';
226 liveuser 155
 
3 liveuser 156
		//放置文字
157
		context2D.fillText('Hello World!',0,0);
226 liveuser 158
 
3 liveuser 159
		";
160
		#可省略參數:
161
		#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
162
		#$conf["onReady"]="true";
163
		#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
164
		#$conf["globalJs"]=array();
165
		#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
166
		#$conf["jsFunciton"]=array();
167
		#參考資料:
168
		#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
169
		#備註:
170
		#無.
171
		$toScript=javaScript::toScript($conf["javaScript::toScript"]);
172
		unset($conf["javaScript::toScript"]);
173
 
174
		#如果建立失敗
175
		if($toScript["status"]==="false"){
226 liveuser 176
 
3 liveuser 177
			#印出結果
178
			var_dump($toScript);
226 liveuser 179
 
3 liveuser 180
			#結束執行
181
			exit;
226 liveuser 182
 
3 liveuser 183
			}#if end
184
 
185
		#印出語法
186
		echo $toScript["content"];
187
 
188
		}#function demo end
189
 
226 liveuser 190
	}#class canvas end