Subversion Repositories php-qbpwcf

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php

/*

        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
    Copyright (C) 2015~2025 Min-Jhin,Chen

    This file is part of QBPWCF.

    QBPWCF is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QBPWCF is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.

*/
namespace qbpwcf;

/*
類別說明:
提供2D、3D繪圖應用的類別.
備註:
無.
*/
class canvas{

        /*
        #函式說明:
        #當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$reuslt["error"],執行不正常結束的錯訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #必填參數:
        #$method,物件,為物件實體或類別名稱,會自動置入該參數.
        #$arguments,陣列,為呼叫方法時所用的參數.
        #參考資料:
        #__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
        */
        public function __call($method,$arguments){

                #取得當前執行的函式
                $result["function"]=__FUNCTION__;

                #設置執行不正常
                $result["status"]="false";

                #設置執行錯誤
                $result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";

                #設置所丟入的參數
                $result["error"][]=$arguments;

                #回傳結果
                return $result;

                }#function __call end

        /*
        #函式說明:
        #當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
        #回傳結果:
        #$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
        #$reuslt["error"],執行不正常結束的錯訊息陣列.
        #$result["function"],當前執行的函式名稱.
        #必填參數:
        #$method,物件,為物件實體或類別名稱,會自動置入該參數.
        #$arguments,陣列,為呼叫方法時所用的參數.
        #參考資料:
        #__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
        */
        public static function __callStatic($method,$arguments){

                #取得當前執行的函式
                $result["function"]=__FUNCTION__;

                #設置執行不正常
                $result["status"]="false";

                #設置執行錯誤
                $result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";

                #設置所丟入的參數
                $result["error"][]=$arguments;

                #回傳結果
                return $result;

                }#function __callStatic end
                
        /*
        #函式說明:
        #展示canvas
        #回傳的結果:
        #回傳結果:
        #無.
        #必填參數:
        #無.
        #可省略參數:
        #無.
        #參考資料:
        #無.
        #備註:
        #無.
        */
        public static function demo(){

                #函式說明:
                #將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
                #回傳結果:
                #$result["status"],執行是否正常,"true"為正常,"false"為不正常.
                #$result["error"],錯誤訊息陣列
                #$result["function"],當前執行的函數名稱
                #$result["content"],要執行的javaScript語法
                #必填參數:
                #$conf["script"],字串,要執行的javaScript語法.
                $conf["javaScript::toScript"]["script"]=
                "
                //建立 canvas
                var canvas=document.createElement('canvas');
                
                //設置寬度為 100%
                canvas.style.width='100%';
                
                //設置高度為 100% - logo
                canvas.style.height='calc( 100% - 20px )';
                
                //放置 canvas
                document.body.prepend(canvas);
                
                //代表要使用2D環境
                var context2D=canvas.getContext('2d');
                
                //設置顏色為全黑
                context2D.fillStyle='#000000';
                
                //繪製矩形,寬為500px,高為300px
                context2D.fillRect(0,0,500,300);
                
                //設置白色
                context2D.fillStyle='#ffffff';
                
                //設置文字大小
                context2D.font='20px Sans-Serif';
                
                //設置對齊方式
                context2D.textBaseline='top';
                
                //放置文字
                context2D.fillText('Hello World!',0,0);
                
                ";
                #可省略參數:
                #$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
                #$conf["onReady"]="true";
                #$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
                #$conf["globalJs"]=array();
                #$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
                #$conf["jsFunciton"]=array();
                #參考資料:
                #http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
                #備註:
                #無.
                $toScript=javaScript::toScript($conf["javaScript::toScript"]);
                unset($conf["javaScript::toScript"]);

                #如果建立失敗
                if($toScript["status"]==="false"){
                
                        #印出結果
                        var_dump($toScript);
                        
                        #結束執行
                        exit;
                
                        }#if end

                #印出語法
                echo $toScript["content"];

                }#function demo end

        }#class canvas end