/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct PlugTextTexture = [ CHTT_instance : PInstance, CHTT_Material : SO3_MATERIAL, CHTT_iTechnique : I, CHTT_iPass : I, CHTT_iTextUnit : I, CHTT_Tex : SO3_TEXTURE, CHTT_OldTex : SO3_TEXTURE, CHTT_iWidth : I, CHTT_iHeight : I, CHTT_bAutoSize : I, CHTT_sText : S, CHTT_iColor : I, CHTT_cvfont : ObjBTFont, CHTT_iBgColor : I, CHTT_bState : I ]mkPlugTextTexture;; fun deleteOb(inst, constr)= if !constr.CHTT_bState then nil else ( SO3MaterialSetTexture constr.CHTT_Material constr.CHTT_OldTex constr.CHTT_iTechnique constr.CHTT_iPass constr.CHTT_iTextUnit; set constr.CHTT_bState = 0; ); SO3TextureDestroy constr.CHTT_Tex; _DSBTfont constr.CHTT_cvfont; 0;; fun getAutoTextureSize(constr, text)= if (text == nil) || (!strcmp text "") then 32 else ( let 20 -> margin in let G2DgetStringSizeBT constr.CHTT_cvfont text -> [tw th] in // nearest 8 multiple ((tw + (multi - 1))&~ (multi - 1)) let 128 -> multi in /*let tw - (mod tw multi) -> twm in let if ((mod tw multi) > (multi / 2)) then twm + multi else twm -> twm in let th - (mod th multi) -> thm in let if ((mod th multi) > (multi / 2)) then thm + multi else thm -> thm in */ let ((tw + margin + (multi - 1))&~ (multi - 1)) -> twm in let ((th + margin + (multi - 1))&~ (multi - 1)) -> thm in if twm >= thm then twm else thm; );; fun cbRevert(inst, from, action, param, reply, constr)= if !constr.CHTT_bState then nil else ( SO3MaterialSetTexture constr.CHTT_Material constr.CHTT_OldTex constr.CHTT_iTechnique constr.CHTT_iPass constr.CHTT_iTextUnit; set constr.CHTT_bState = 0; ); 0;; fun drawTextureText(constr, text)= if constr.CHTT_bState then nil else ( SO3MaterialSetTexture constr.CHTT_Material constr.CHTT_Tex constr.CHTT_iTechnique constr.CHTT_iPass constr.CHTT_iTextUnit; set constr.CHTT_bState = 1; ); if (constr.CHTT_bAutoSize) then ( let getAutoTextureSize constr text -> nsize in let _FILLbitmap (_CRbitmap _channel nsize nsize) constr.CHTT_iBgColor -> bmp in ( SO3TextureDestroy constr.CHTT_Tex; //_DLGMessageBox _channel nil "test" strcat ">> " itoa nsize 0; set constr.CHTT_Tex = SO3TextureCreate (V3DgetSession c3dXsession) strcat (getPluginInstanceName constr.CHTT_instance) ".textTexure" nil (getPluginInstanceGroupName constr.CHTT_instance) nsize nsize; SO3MaterialSetTexture constr.CHTT_Material constr.CHTT_Tex constr.CHTT_iTechnique constr.CHTT_iPass constr.CHTT_iTextUnit; let G2DgetStringSizeBT constr.CHTT_cvfont text -> [_ th] in _BTDRAWtextAreaBitmap bmp constr.CHTT_cvfont [0 0 nsize nsize] [0 0] BT_TEXT_HORIZ_CENTERED|BT_TEXT_VERT_CENTER|BT_TEXT_WORD_WRAP constr.CHTT_iColor text; SO3TextureBlit constr.CHTT_Tex bmp; _DSbitmap bmp; ); ) else ( let _FILLbitmap (_CRbitmap _channel constr.CHTT_iWidth constr.CHTT_iHeight) constr.CHTT_iBgColor -> bmp in ( let G2DgetStringSizeBT constr.CHTT_cvfont text -> [_ th] in _BTDRAWtextAreaBitmap bmp constr.CHTT_cvfont [0 0 constr.CHTT_iWidth constr.CHTT_iHeight] [0 0] BT_TEXT_HORIZ_CENTERED|BT_TEXT_VERT_CENTER|BT_TEXT_WORD_WRAP constr.CHTT_iColor text; SO3TextureBlit constr.CHTT_Tex bmp; _DSbitmap bmp; ); ); 0;; fun cbSetText(inst, from, action, param, reply, constr)= drawTextureText constr param; 0;; fun cbAddText(inst, from, action, param, reply, constr)= drawTextureText constr strcatn constr.CHTT_sText::"\n"::param::nil; 0;; /** * * TODO _DRAWrectangleText mode * align params * **/ fun newOb(inst)= let (getPluginInstanceParam inst "object") -> objname in let (getPluginInstanceParam inst "material") -> matname in let atoi (getPluginInstanceParam inst "technique") -> technique in let if technique == nil then 0 else technique -> technique in let atoi (getPluginInstanceParam inst "pass") -> pass in let if pass == nil then 0 else pass -> pass in let atoi (getPluginInstanceParam inst "texture") -> texture in let if texture == nil then 0 else texture -> texture in let atoi (getPluginInstanceParam inst "texwidth") -> texwidth in let if texwidth == nil then 512 else texwidth -> texwidth in let atoi (getPluginInstanceParam inst "texheight") -> texheight in let if texheight == nil then 512 else texheight -> texheight in let atoi (getPluginInstanceParam inst "autosize") -> autosize in let if autosize == nil then 0 else autosize -> autosize in let atoi (getPluginInstanceParam inst "bgcolor") -> bgcolor in let if bgcolor == nil then 0xffffff else bgcolor -> bgcolor in let getPluginInstanceParam inst "fontname" -> fname in let if fname == nil then "Arial" else fname -> fname in let atoi (getPluginInstanceParam inst "color") -> color in let if color == nil then 0 else color -> color in let atoi (getPluginInstanceParam inst "fontsize") -> fsize in let if fsize == nil then 12 else fsize -> fsize in let atoi (getPluginInstanceParam inst "fontbold") -> fbold in let if fbold == nil then 0 else fbold -> fbold in let getPluginInstanceParam inst "text" -> text in let atoi (getPluginInstanceParam inst "init") -> init in let if init == nil then 1 else init -> init in //let G2DcrFont _channel fsize 0 FF_PIXEL|(if fbold then FF_WEIGHT else 0) fname -> font in let _CRBTfont _channel fname fsize (BT_FONT_ANTIALIAS | (if fbold then BT_FONT_BOLD else 0)) 1.0 -> cv_font in let SO3SceneGetObject (V3DgetSession c3dXsession) objname -> obj in let SO3SceneGetMaterial (V3DgetSession c3dXsession) (SO3EntityGetResourceGroup obj) matname -> mat in let SO3MaterialGetTexture mat technique pass texture -> otex in let mkPlugTextTexture [inst mat technique pass texture nil otex nil nil autosize text color cv_font bgcolor 0] -> constr in ( let if autosize then getAutoTextureSize constr text else 0 -> defsize in let if autosize then defsize else texwidth -> texwidth in let if autosize then defsize else texheight -> texheight in let SO3TextureCreate (V3DgetSession c3dXsession) strcat (getPluginInstanceName inst) ".textTexure" nil (getPluginInstanceGroupName inst) texwidth texheight -> tex in ( set constr.CHTT_Tex = tex; set constr.CHTT_iWidth = texwidth; set constr.CHTT_iHeight = texheight; ); if !init then nil else ( drawTextureText constr text; 0; ); PluginRegisterAction inst "Set text" mkfun6 @cbSetText constr; PluginRegisterAction inst "Add text" mkfun6 @cbAddText constr; PluginRegisterAction inst "Revert" mkfun6 @cbRevert constr; setPluginInstanceCbDel inst mkfun2 @deleteOb constr; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;