*/}}

la_widgets_viewers.c 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "../la_5.h"
  19. extern LA MAIN;
  20. extern struct _tnsMain *T;
  21. //============================================================= [Draw]
  22. extern tnsFontManager *FM;
  23. void la_SetCanvasOrtho(laCanvasExtra* e,int W, int H){
  24. real x2=(real)W*e->ZoomX/2,y2=(real)H*e->ZoomY/2;
  25. tnsOrtho(e->PanX-x2,e->PanX+x2,e->PanY-y2,e->PanY+y2,-100,100);
  26. tnsVector3d dir={0,0,-1}; tnsSetCameraViewDir(dir);
  27. }
  28. void la_SetCanvasOrthoFixed(laCanvasExtra* e,int W, int H){
  29. real x2=(real)W/LA_RH/2,y2=(real)H/LA_RH/2;
  30. tnsOrtho(-x2,+x2,-y2,+y2,-100,100);
  31. tnsVector3d dir={0,0,-1}; tnsSetCameraViewDir(dir);
  32. }
  33. void la_BeginNVG(NVGcontext* vg,laCanvasExtra* e,int W,int H, int Is2D){
  34. nvgBeginFrame(vg,W,H,1);
  35. if(Is2D){
  36. nvgTranslate(vg,-e->PanX/e->ZoomX+W/2,e->PanY/e->ZoomY+H/2);
  37. nvgScale(vg,1.0f/e->ZoomX,1.0f/e->ZoomY);
  38. }else{
  39. nvgTranslate(vg,W/2,H/2);
  40. nvgScale(vg,1,-1);
  41. }
  42. }
  43. void la_BeginNVGFixed(NVGcontext* vg,laCanvasExtra* e,int W,int H){
  44. nvgBeginFrame(vg,W,H,1); nvgTranslate(vg,W/2,H/2); nvgScale(vg,LA_RH,LA_RH);
  45. }
  46. void la_BeginNVGDynamic(NVGcontext* vg,laCanvasExtra* e,int W,int H, int Is2D, int OverrideFixed){
  47. if(OverrideFixed)la_BeginNVGFixed(vg,e,W,H);
  48. else la_BeginNVG(vg,e,W,H,Is2D);
  49. }
  50. void la_RootObjectDrawFullscreenQuad(tnsOffscreen* DeferredOffScr,tnsCamera* c, real Aspect){
  51. real FOV = c->FOV;
  52. tnsMatrix44d mat;
  53. tnsGetMVMatrix(mat);
  54. real vv[3]={0,0,-1};
  55. real ViewDir[3]={0},vdTR[3]={0},vdBR[3]={0},vdTL[3]={0},vdBL[3]={0};
  56. tnsApplyRotation43d(ViewDir,mat,vv);
  57. real fovv=FOV/2, fovh=fovh=atan(tan(FOV/2)*Aspect);
  58. vv[0]=tan(fovh); vv[1]=tan(fovv); tnsApplyRotation43d(vdTR,mat,vv); // note don't normalize those.
  59. vv[0]=tan(fovh); vv[1]=tan(-fovv);tnsApplyRotation43d(vdBR,mat,vv);
  60. vv[0]=tan(-fovh);vv[1]=tan(-fovv);tnsApplyRotation43d(vdBL,mat,vv);
  61. vv[0]=tan(-fovh);vv[1]=tan(fovv); tnsApplyRotation43d(vdTL,mat,vv);
  62. tnsUseRayShader();
  63. tnsEnableShaderv(T->RayShader);
  64. tnsSetRayShaderUniformTextures(DeferredOffScr);
  65. real uv[12]; tnsMakeQuad3d(uv, LA_COLOR3(vdTL), LA_COLOR3(vdTR), LA_COLOR3(vdBR), LA_COLOR3(vdBL));
  66. real vt[8]; tnsMakeQuad2d(vt, -1,1, 1,1, 1,-1, -1,-1);
  67. tnsTexCoordArray3d(uv,4);
  68. tnsVertexArray2d(vt,4);
  69. tnsPackAs(GL_TRIANGLE_FAN);
  70. glUniform3f(T->RayShader->uViewDir,LA_COLOR3(ViewDir));
  71. glUniform3f(T->RayShader->uViewPos,LA_COLOR3(c->Base.Location));
  72. glUniform1f(T->RayShader->uFOV,FOV);
  73. tnsFlush();
  74. tnsUseImmShader();
  75. }
  76. #define LA_DEPTH_RESOLUTION 1024
  77. void la_3DViewEnsureCamera(laCanvasExtra* e);
  78. void la_RootObjectDraw(laBoxedTheme *bt, tnsObject *root, laUiItem* ui){
  79. laCanvasExtra *e = ui->Extra;
  80. la_3DViewEnsureCamera(e);
  81. tnsCamera *c = e->UsingCamera ? e->UsingCamera : e->ViewingCamera;
  82. int W, H; W = ui->R - ui->L; H = ui->B - ui->U; if (W<=0 || H<=0) return;
  83. tnsFlush();
  84. if (!e->OffScr){
  85. //e->OffScr = tnsCreateDeferredOffscreen(W,H,MAIN.PanelMultisample);
  86. e->OffScr = tnsCreate2DOffscreen(GL_RGBA, W, H, MAIN.PanelMultisample ,1, 1);
  87. }else{ tnsEnsureOffscreenStatus(e->OffScr, ui->R - ui->L, ui->B - ui->U); }
  88. if (0){//(e->CurrentScene && e->CurrentScene->ActiveSun){
  89. //if(!e->OffScrShadow) e->OffScrShadow = tnsCreate2DOffscreen(0, LA_DEPTH_RESOLUTION, LA_DEPTH_RESOLUTION, MAIN.PanelMultisample, 1, 0);
  90. //tnsUseNoTexture();
  91. //tnsDrawToOffscreen(e->OffScrShadow, 1, TNS_ATTACHMENT_ARRAY_NONE);
  92. //tnsViewportWithScissor(0,0,LA_DEPTH_RESOLUTION,LA_DEPTH_RESOLUTION);
  93. //glEnable(GL_DEPTH_TEST);
  94. //glClearDepth(1.0); glClear(GL_DEPTH_BUFFER_BIT);
  95. //tnsResetViewMatrix();tnsResetModelMatrix();tnsResetProjectionMatrix();
  96. //tnsEnableShaderv(T->ShadowShader);
  97. //tnsUseShadowShader();
  98. //tnsApplyShadowCameraView(e->CurrentScene->ActiveSun);
  99. //
  100. //real p[12];
  101. //tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  102. //tnsMakeQuad3d(p, -100,-100, 25,-100,100, 25,100,100, 25,100,-100, 25);
  103. //tnsVertexArray3d(p, 4); tnsPackAs(GL_TRIANGLE_FAN);
  104. //tnsMakeQuad3d(p, -100,-100, 74,-100,100, 74,100,100, 74,100,-100, 74);
  105. //tnsVertexArray3d(p, 4); tnsPackAs(GL_TRIANGLE_FAN);
  106. ////tnsDrawFloor(e->ViewingCamera->Base.GLocation, e->ViewingCamera->ZMax, e->ShowAxis);
  107. //tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  108. //tnsDrawFloor(e->ViewingCamera->Base.GLocation, e->ViewingCamera->ZMax, e->ShowAxis);
  109. //tnsEnableShaderv(T->immShader);
  110. //tnsFlush();
  111. tnsDrawToOffscreen(e->OffScr,1,0);
  112. tnsViewportWithScissor(0, 0, W, H);
  113. tnsClearColorv(laThemeColor(bt,LA_BT_NORMAL));
  114. tnsClearAll();
  115. //tnsUseSceneShader();
  116. //tnsEnableShaderv(T->SceneShader);
  117. //tnsApplyShadowCameraView(e->CurrentScene->ActiveSun);
  118. tnsApplyCameraView(W, H, c,0,0);
  119. //
  120. //tnsUseTexture(e->OffScrShadow->pDepth);
  121. //
  122. //tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  123. //tnsMakeQuad3d(p, -100,-100, 25,-100,100, 25,100,100, 25,100,-100, 25);
  124. //tnsVertexArray3d(p, 4); tnsPackAs(GL_TRIANGLE_FAN);
  125. //tnsMakeQuad3d(p, -100,-100, 74,-100,100, 74,100,100, 74,100,-100, 74);
  126. //tnsVertexArray3d(p, 4); tnsPackAs(GL_TRIANGLE_FAN);
  127. //tnsUseNoTexture();
  128. //if (e->ShowFloorGrid){
  129. // tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  130. // tnsDrawFloor(e->ViewingCamera->Base.GLocation, e->ViewingCamera->ZMax, e->ShowAxis);
  131. // tnsFlush();
  132. //}
  133. //
  134. //tnsFlush();
  135. }else if(e->OffScrShadow){ tnsDelete2DOffscreen(e->OffScrShadow); }
  136. //{
  137. // tnsDrawToOffscreen(e->OffScr, 1, 0);
  138. // //tnsUseShader(T->TEST_MatcapShader);
  139. // tnsEnableShaderv(T->TEST_MatcapShader);
  140. // tnsViewportWithScissor(0, 0, W, H);
  141. // tnsClearColorv(laThemeColor(bt,LA_BT_NORMAL));
  142. // tnsClearAll();
  143. //}
  144. tnsDrawToOffscreen(e->OffScr,3,TNS_ATTACHMENT_ARRAY_0_1_2);
  145. //tnsDrawToOffscreen(e->DeferredOffScr,3,TNS_ATTACHMENT_ARRAY_0_1_2);
  146. tnsViewportWithScissor(0, 0, W, H); glDepthMask(GL_TRUE);
  147. tnsClearColorv(laThemeColor(bt,LA_BT_NORMAL)); tnsClearAll(); float gpos_clear[]={-1e20, -1e20, -1e20, 0};
  148. glClearBufferfv(GL_COLOR, 2, gpos_clear);
  149. la3DObjectDrawExtra de={0};
  150. de.MeshEditType=e->SelectMode; de.DisplayMode=e->AsPlayer?LA_CANVAS_DISPLAY_MATERIAL:e->DisplayMode;
  151. de.W=W; de.H=H; de.PointScale=1.0f/LA_RH;
  152. tnsRootObject* ro=root;
  153. NVGcontext* vg=MAIN.CurrentWindow->nvg;
  154. tnsMatrix44d mview,mproj;
  155. if(ro && ro->Is2D){ la_SetCanvasOrtho(e,W,H); de.PointScale=e->ZoomX; }
  156. else{
  157. if(ro && ro->ActiveCamera && e->AsPlayer){ c=ro->ActiveCamera; }
  158. tnsApplyCameraView(W, H, c, mview,mproj); tnsMultiply44d(de.mViewProj,mproj,mview); de.Is3D=1;
  159. }
  160. tnsPushMatrix(); tnsPopMatrix(); //those are necessary when ui is the first in list;
  161. if(root){
  162. tnsPushMatrix();
  163. if(!e->AsPlayer){
  164. tnsSetObjectTreeEvaluationArgs(root,root->Active,1,1,W,H);
  165. tnsEvaluateObjectTree(root,0,0);
  166. }
  167. if(ro && e->AsPlayer && ro->ActiveCamera && !ro->Is2D){ c=ro->ActiveCamera; c=c->Base.PlayDuplicate?c->Base.PlayDuplicate:c;
  168. tnsApplyCameraView(W, H, c,0,0);
  169. }
  170. for(int i=0;i<2;i++){
  171. int Do2DInstance=(i==1)?TNS_EVAL_LAYER_SHOW_2D:0;
  172. int Is2D=(i==1)?1:ro->Is2D;
  173. if (Do2DInstance){
  174. la_SetCanvasOrthoFixed(e,W,H); de.PointScale=1.0f/LA_RH; de.Is3D=0;
  175. tnsResetViewMatrix(); tnsShaderApplyView(T->BindedShader,tnsGetViewMatrix());
  176. }
  177. la_BeginNVGDynamic(vg,e,W,H,Is2D,Do2DInstance);
  178. tnsDrawObjectTree(root,TNS_EVAL_LAYER_BACKDROP|Do2DInstance,&de,e->AsPlayer);
  179. nvgEndFrame(vg); tnsRestoreFromNanoVG();
  180. la_BeginNVGDynamic(vg,e,W,H,Is2D,Do2DInstance);
  181. glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND);
  182. tnsUseShader(T->immShader); tnsEnableShaderv(T->immShader); tnsUseNoTexture();
  183. tnsUnbindTexture(); tnsUniformUseTexture(T->immShader,0,0); tnsUseMultiplyColor(0);
  184. tnsDrawObjectTree(root,TNS_EVAL_LAYER_SOLID|Do2DInstance,&de,e->AsPlayer);
  185. glLineWidth(7); tnsUniformUseOffset(T->immShader,-100);
  186. glDepthMask(GL_FALSE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  187. tnsDrawObjectTree(root,TNS_EVAL_LAYER_OUTLINE|Do2DInstance,0,e->AsPlayer);
  188. glDepthMask(GL_TRUE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  189. glLineWidth(1); tnsUniformUseOffset(T->immShader,0);
  190. tnsEvaluateData* ed=e->AsPlayer?(&root->EvaluatedPlay):(&root->Evaluated);
  191. if(!ed->Has2D){ break; }
  192. nvgEndFrame(vg); tnsRestoreFromNanoVG();
  193. }
  194. tnsPopMatrix();
  195. }
  196. if(!(ro && ro->Is2D)){ de.Is3D=1; tnsVector3d dir={0,0,0}; tnsSetCameraViewDir(dir); }
  197. if (e->ShowFloorGrid && (!e->AsPlayer)){
  198. tnsUseNoTexture();
  199. real* color=laThemeColor(bt,LA_BT_BORDER); tnsColor4d(LA_COLOR3(color),0.4);
  200. tnsDrawFloor(e->ViewingCamera->Base.GLocation, e->ViewingCamera->ZMax, e->ShowAxis);
  201. tnsFlush();
  202. }
  203. if(e->SelectThrough){ glClear(GL_DEPTH_BUFFER_BIT); }
  204. tnsDrawObjectTree(root,TNS_EVAL_LAYER_OVERLAY,&de,e->AsPlayer);
  205. if(root && (!e->AsPlayer)){
  206. glDisable(GL_DEPTH_TEST);
  207. glPointSize(8); tnsDrawCursor(root);
  208. tnsDrawObjectOrigins(root,root->Active,0); tnsFlush();
  209. glPointSize(1); glEnable(GL_DEPTH_TEST);
  210. }
  211. //laInvoke(0,"M_select",e,&ui->ExtraPP,0,0);
  212. //glColorMask(GL_FALSE, GL_FALSE,GL_FALSE,GL_FALSE);
  213. //tnsEvaluateObjectTree(e->CurrentScene, 0,0);
  214. tnsFlush();
  215. //glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
  216. glDisable(GL_DEPTH_TEST); glEnable(GL_BLEND);
  217. nvgEndFrame(vg); tnsRestoreFromNanoVG();
  218. //tnsDrawToOffscreen(e->OffScr, 1,0);
  219. //tnsClearColorv(laThemeColor(bt,LA_BT_NORMAL)); tnsClearAll();
  220. //la_RootObjectDrawFullscreenQuad(e->DeferredOffScr, c, (real)W/(real)H);
  221. }
  222. void la_RootObjectDrawOverlay(laUiItem *ui, int h){
  223. laCanvasExtra *e = ui->Extra;
  224. laBoxedTheme *bt = (*ui->Type->Theme);
  225. tnsUseHalftone(MAIN.ViewportHalftoneFactor);
  226. tnsUniformHalftoneSize(T->immShader,MAIN.ViewportHalftoneSize);
  227. tnsDraw2DTextureDirectly(e->OffScr->pColor[0], ui->L, ui->U, ui->R - ui->L, ui->B - ui->U);
  228. tnsUseHalftone(0);
  229. //if(e->OffScrShadow){
  230. //tnsDraw2DTextureDirectly(e->OffScrShadow->pDepth, ui->L, ui->U, ui->R - ui->L, ui->B - ui->U);
  231. //}
  232. tnsUseNoTexture();
  233. if (e->DrawCursor){
  234. if(e->DrawCursor==LA_CANVAS_CURSOR_ARROW){
  235. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT));
  236. tnsVertex2d(e->OnX, e->OnY); tnsVertex2d(e->TargetX, e->TargetY);
  237. tnsPackAs(GL_LINES);
  238. }else{
  239. if(e->DrawCursor==LA_CANVAS_CURSOR_BOX){
  240. tnsColor4dv(laAccentColor(LA_BT_NORMAL));
  241. tnsVertex2d(e->ClickedX, e->ClickedY); tnsVertex2d(e->ClickedX, e->OnY);
  242. tnsVertex2d(e->OnX, e->OnY); tnsVertex2d(e->OnX, e->ClickedY);
  243. tnsPackAs(GL_TRIANGLE_FAN);
  244. tnsColor4dv(laAccentColor(LA_BT_TEXT));
  245. tnsVertex2d(e->ClickedX, e->ClickedY); tnsVertex2d(e->ClickedX, e->OnY);
  246. tnsVertex2d(e->OnX, e->OnY); tnsVertex2d(e->OnX, e->ClickedY);
  247. tnsPackAs(GL_LINE_LOOP);
  248. }
  249. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT));
  250. int drawx=(e->DrawCursor==LA_CANVAS_CURSOR_CROSS)||(e->DrawCursor==LA_CANVAS_CURSOR_X);
  251. int drawy=(e->DrawCursor==LA_CANVAS_CURSOR_CROSS)||(e->DrawCursor==LA_CANVAS_CURSOR_Y);
  252. if(drawx){ tnsVertex2d(e->OnX, ui->U); tnsVertex2d(e->OnX, ui->B); }
  253. if(drawy){ tnsVertex2d(ui->L, e->OnY); tnsVertex2d(ui->R, e->OnY); }
  254. tnsPackAs(GL_LINES);
  255. }
  256. }
  257. if(MAIN.CurrentWindow->MaximizedUi!=ui){
  258. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  259. tnsVertex2d(ui->L, ui->U);
  260. tnsVertex2d(ui->R, ui->U);
  261. tnsVertex2d(ui->R, ui->B);
  262. tnsVertex2d(ui->L, ui->B);
  263. tnsPackAs(GL_LINE_LOOP);
  264. }
  265. tnsFlush();
  266. char* MaxIco=(MAIN.CurrentWindow->MaximizedUi!=ui)?"🡹":"🡻";
  267. tnsVector4d color; tnsVectorCopy4d(laThemeColor(bt,LA_BT_TEXT),color);
  268. tnsVector4d colork; tnsVectorCopy4d(laThemeColor(bt,LA_BT_NORMAL),colork);
  269. color[3]=ui->State==LA_UI_NORMAL?0.0:(ui->State==LA_UI_ACTIVE?0.5:1.0);
  270. colork[3]=ui->State==LA_UI_NORMAL?0.0:(ui->State==LA_UI_ACTIVE?0.5:1.0);
  271. int startx=(ui->R+ui->L)/2-LA_RH2*2;
  272. int offs=LA_RH/12;
  273. tnsDrawStringAuto("☰",colork,startx+offs, startx+LA_RH+offs, ui->B-bt->BM-LA_RH+offs, LA_TEXT_ALIGN_CENTER);
  274. tnsDrawStringAuto("☰",color,startx, startx+LA_RH, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_CENTER);
  275. tnsDrawStringAuto(MaxIco,colork,startx+LA_RH+offs, startx+LA_2RH+offs, ui->B-bt->BM-LA_RH+offs, LA_TEXT_ALIGN_CENTER);
  276. tnsDrawStringAuto(MaxIco,color,startx+LA_RH, startx+LA_2RH, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_CENTER);
  277. if(ui->Expand>=0 && ui!=MAIN.CurrentWindow->MaximizedUi){
  278. tnsDrawStringAuto("◿",colork,ui->R-LA_RH+offs, ui->R+offs, ui->B-bt->BM-LA_RH+offs, LA_TEXT_ALIGN_CENTER);
  279. tnsDrawStringAuto("◿",laThemeColor(bt,LA_BT_BORDER),ui->R-LA_RH, ui->R, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_CENTER);
  280. }
  281. tnsFlush();
  282. }
  283. void la_CanvasDrawTexture(laBoxedTheme *bt, tnsTexture *t, laUiItem* ui){
  284. laCanvasExtra* e=ui->Extra;
  285. int W, H; W = ui->R - ui->L; H = ui->B - ui->U;
  286. if (W<=0 || H<=0) return;
  287. tnsFlush();
  288. if (!e->OffScr || e->OffScr->pColor[0]->Height != ui->B - ui->U || e->OffScr->pColor[0]->Width != ui->R - ui->L){
  289. if (e->OffScr) tnsDelete2DOffscreen(e->OffScr);
  290. e->OffScr = tnsCreate2DOffscreen(GL_RGBA, W, H, MAIN.PanelMultisample, 1, 0);
  291. }
  292. tnsDrawToOffscreen(e->OffScr, 1, 0);
  293. tnsViewportWithScissor(0, 0, W, H);
  294. tnsResetViewMatrix();tnsResetModelMatrix();tnsResetProjectionMatrix();
  295. la_SetCanvasOrtho(e,W,H);
  296. //glClearColor(0.3,0.3,0.3, 1);
  297. if (e->ClearBackground){ tnsClearColorv(laThemeColor(bt,LA_BT_NORMAL)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
  298. // above is basic routine setup
  299. real V[8] = {0};
  300. real UV[8] = {0};
  301. if (t){
  302. real w2=t->Width/2, h2=t->Height/2;
  303. tnsDraw2DTextureDirectly(t, -w2, h2, t->Width, -t->Height);
  304. tnsFlush();
  305. if (e->ImageDrawBorder){
  306. tnsUseNoTexture();
  307. tnsMakeQuad2d(V, -w2, -h2, -w2, h2, w2, h2, w2, -h2);
  308. tnsVertexArray2d(V, 4);
  309. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  310. tnsVertexArray2d(V, 4);
  311. tnsPackAs(GL_LINE_LOOP);
  312. tnsFlush();
  313. }
  314. }
  315. }
  316. real la_CanvasDrawGetDisplayStep(real Max, real Min, int AreaSize){
  317. real r;
  318. real Step = 1.0;
  319. real DispW;
  320. real Div[3] = {2.0, 2.5, 2.0};
  321. int Times = 302;
  322. while (1){
  323. Times++;
  324. r = tnsGetRatiod(0, Max - Min, Step);
  325. DispW = tnsLinearItp(0, AreaSize, r);
  326. if (DispW > 100){
  327. Step /= Div[Times % 3];
  328. }elif (DispW < 40){
  329. Step *= Div[Times % 3];
  330. }else break;
  331. }
  332. return Step;
  333. }
  334. void la_CanvasDrawGridW(real Ratio, int RealW, real Min, real Max, real U, real B){
  335. real t;
  336. real Step = la_CanvasDrawGetDisplayStep(Max, Min, RealW);
  337. t = (real)((int)(Min / Step)) * Step;
  338. for (t; t <= Max; t += Step){
  339. tnsVertex2d(t, U);
  340. tnsVertex2d(t, B);
  341. tnsPackAs(GL_LINES);
  342. }
  343. }
  344. void la_CanvasDrawGridH(real Ratio, int RealH, real Min, real Max, real L, real R){
  345. real t;
  346. real Step = la_CanvasDrawGetDisplayStep(Max, Min, RealH);
  347. t = (real)((int)(Min / Step)) * Step;
  348. for (t; t <= Max; t += Step){
  349. tnsVertex2d(L, t);
  350. tnsVertex2d(R, t);
  351. tnsPackAs(GL_LINES);
  352. }
  353. }
  354. void la_CanvasDrawRulerW(real Ratio, laBoxedTheme *bt, int RealW, real Min, real Max, int B){
  355. char buf[20] = {0};
  356. real t, IL;
  357. real Step = la_CanvasDrawGetDisplayStep(Max, Min, RealW);
  358. int U = B - LA_RH;
  359. tnsUseNoTexture();
  360. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  361. tnsVertex2d(0, U);
  362. tnsVertex2d(RealW, U);
  363. tnsVertex2d(RealW, B);
  364. tnsVertex2d(0, B);
  365. tnsPackAs(GL_TRIANGLE_FAN);
  366. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT_ACTIVE));
  367. tnsVertex2d(0, U + 0.5);
  368. tnsVertex2d(RealW, U + 0.5);
  369. tnsPackAs(GL_LINES);
  370. t = (real)((int)(Min / Step)) * Step;
  371. for (t; t <= Max; t += Step){
  372. IL = tnsGetRatiod(Min, Max, t) * (RealW);
  373. sprintf(buf, "%.0f", t);
  374. tnsDrawStringAuto(buf, bt->Active, IL, IL + 100, U, 0);
  375. }
  376. }
  377. void la_CanvasDrawRulerRWithBkg(real Ratio, laBoxedTheme *bt, int RealH, real Min, real Max, int R){
  378. real t, OrigT;
  379. char buf[50][20] = {0};
  380. real IL[50];
  381. int i = 0;
  382. int W = 0, MaxW = 0;
  383. int RH = LA_RH, hH = RH / 2;
  384. int L;
  385. real Step = la_CanvasDrawGetDisplayStep(Max, Min, RealH);
  386. int IS = Step > 1 ? 0 : (Step > 0.09 ? 1 : 2);
  387. t = OrigT = (real)((int)(Min / Step)) * Step;
  388. for (t; t <= Max; t += Step, i++){
  389. sprintf(buf[i], "%.*f", IS, t);
  390. W = tnsStringGetWidth(buf[i], 0, 0);
  391. if (W > MaxW) MaxW = W;
  392. }
  393. L = R - MaxW - 4;
  394. tnsUseNoTexture();
  395. for (t = OrigT, i = 0; t <= Max; t += Step, i++){
  396. IL[i] = tnsGetRatiod(Max, Min, t) * (RealH);
  397. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  398. tnsVertex2d(R, IL[i] - hH);
  399. tnsVertex2d(R, IL[i] + hH);
  400. tnsVertex2d(L, IL[i] + hH);
  401. tnsVertex2d(L, IL[i] - hH);
  402. tnsPackAs(GL_TRIANGLE_FAN);
  403. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT_ACTIVE));
  404. tnsVertex2d(R, IL[i] - hH);
  405. tnsVertex2d(R, IL[i] + hH);
  406. tnsVertex2d(L, IL[i] + hH);
  407. tnsVertex2d(L, IL[i] - hH);
  408. tnsPackAs(GL_LINE_LOOP);
  409. }
  410. for (t = OrigT, i = 0; t <= Max; t += Step, i++){
  411. tnsDrawStringAuto(buf[i], bt->Active, L + 2, R, IL[i] - hH, 0);
  412. }
  413. }
  414. void la_CanvasDraw(laUiItem *ui, int h){
  415. laBoxedTheme *bt = (*ui->Type->Theme);
  416. if (ui->CanvasTemplate && ui->CanvasTemplate->Draw) ui->CanvasTemplate->Draw(bt, ui->PP.EndInstance, ui);
  417. }
  418. void la_CanvasDefaultOverlay(laUiItem* ui, int h){
  419. laCanvasExtra *e = ui->Extra;
  420. laBoxedTheme *bt = (*ui->Type->Theme);
  421. tnsUseNoTexture();
  422. if(MAIN.CurrentWindow->MaximizedUi!=ui){
  423. tnsColor4dv(laThemeColor(bt,LA_BT_BORDER));
  424. tnsVertex2d(ui->L, ui->U); tnsVertex2d(ui->R, ui->U);
  425. tnsVertex2d(ui->R, ui->B); tnsVertex2d(ui->L, ui->B);
  426. tnsPackAs(GL_LINE_LOOP);
  427. }
  428. if (e->DrawCursor){
  429. tnsColor4dv(laThemeColor(bt,LA_BT_TEXT));
  430. int drawx=(e->DrawCursor==LA_CANVAS_CURSOR_CROSS)||(e->DrawCursor==LA_CANVAS_CURSOR_X);
  431. int drawy=(e->DrawCursor==LA_CANVAS_CURSOR_CROSS)||(e->DrawCursor==LA_CANVAS_CURSOR_Y);
  432. if(drawx) tnsVertex2d(e->OnX, ui->U); tnsVertex2d(e->OnX, ui->B);
  433. if(drawy) tnsVertex2d(ui->L, e->OnY); tnsVertex2d(ui->R, e->OnY);
  434. tnsPackAs(GL_LINES);
  435. tnsFlush();
  436. }
  437. char* MaxIco=(MAIN.CurrentWindow->MaximizedUi!=ui)?"🡹":"🡻";
  438. tnsVector4d color; tnsVectorCopy4d(laThemeColor(bt,LA_BT_TEXT),color);
  439. tnsVector4d colork; tnsVectorCopy4d(laThemeColor(bt,LA_BT_NORMAL),colork);
  440. color[3]=ui->State==LA_UI_NORMAL?0.0:(ui->State==LA_UI_ACTIVE?0.5:1.0);
  441. colork[3]=ui->State==LA_UI_NORMAL?0.0:(ui->State==LA_UI_ACTIVE?0.5:1.0);
  442. int startx=(ui->R+ui->L)/2-LA_RH2*2;
  443. int offs=LA_RH/12;
  444. tnsDrawStringAuto("☰",colork,startx+offs, startx+LA_RH+offs, ui->B-bt->BM-LA_RH+offs, LA_TEXT_ALIGN_CENTER);
  445. tnsDrawStringAuto("☰",color,startx, startx+LA_RH, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_CENTER);
  446. tnsDrawStringAuto(MaxIco,colork,startx+LA_RH+offs, startx+LA_2RH+offs, ui->B-bt->BM-LA_RH+offs, LA_TEXT_ALIGN_CENTER);
  447. tnsDrawStringAuto(MaxIco,color,startx+LA_RH, startx+LA_2RH, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_CENTER);
  448. if(ui->Expand>=0 && ui!=MAIN.CurrentWindow->MaximizedUi){
  449. tnsDrawStringAuto("◿",colork,ui->R-LA_RH+offs, ui->R+offs, ui->B-bt->BM-LA_RH+offs, LA_TEXT_ALIGN_CENTER);
  450. tnsDrawStringAuto("◿",laThemeColor(bt,LA_BT_BORDER),ui->R-LA_RH, ui->R, ui->B-bt->BM-LA_RH, LA_TEXT_ALIGN_CENTER);
  451. }
  452. tnsFlush();
  453. }
  454. void la_CanvasDrawOverlay(laUiItem *ui, int h){
  455. laCanvasExtra *e = ui->Extra;
  456. laBoxedTheme *bt = (*ui->Type->Theme);
  457. tnsDraw2DTextureDirectly(e->OffScr->pColor[0], ui->L, ui->U, ui->R - ui->L, ui->B - ui->U);
  458. la_CanvasDefaultOverlay(ui, h);
  459. }
  460. int la_AnimateUiListRecursive(laUiList *uil);
  461. void laDefault3DViewOverlay(laUiItem *ui){
  462. laUiList *uil, *gu,*muil,*gu2;
  463. laColumn *c, *cl, *cr, *gc, *gcl, *gcr, *mc,*gc2;
  464. laPropPack *e = &ui->ExtraPP;
  465. laUiItem *b, *g, *b1, *b2,*g2;
  466. if (!(uil = ui->Subs.pFirst)) uil = laAddTabPage(ui, "New Group");
  467. c = laFirstColumn(uil);
  468. laSplitColumn(uil, c, 0.8); cl = laLeftColumn(c, 0); cr = laRightColumn(c, 0);
  469. b=laBeginRow(uil,c,0,0);
  470. laUiItem* activeui=laShowInvisibleItem(uil,c,&ui->PP,"active");
  471. muil=laMakeMenuPage(uil,c,"👁"); mc=laFirstColumn(muil);{
  472. laSplitColumn(muil, mc, 0.3); gcl = laLeftColumn(mc, 0); gcr = laRightColumn(mc, 0);
  473. laShowLabel(muil,gcl,"Floor:",0,0); laShowLabel(muil,gcr,"Axis:",0,0);
  474. laShowItem(muil,gcl,&ui->ExtraPP,"show_floor_grid")->Flags|=LA_UI_FLAGS_ICON|LA_UI_FLAGS_CYCLE;
  475. laShowItem(muil,gcr,&ui->ExtraPP,"show_axis")->Flags|=LA_UI_FLAGS_TRANSPOSE|LA_UI_FLAGS_ICON;
  476. }
  477. muil=laMakeMenuPage(uil,c,"Transform"); mc=laFirstColumn(muil);{
  478. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_grab");
  479. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_scale");
  480. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_rotate");
  481. laShowSeparator(muil,mc);
  482. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_clear_transformations");
  483. }
  484. muil=laMakeMenuPage(uil,c,"Object"); mc=laFirstColumn(muil);{
  485. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_add");
  486. laShowSeparator(muil,mc);
  487. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_make_parent");
  488. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_unparent");
  489. laShowSeparator(muil,mc);
  490. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_duplicate");
  491. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_combine");
  492. laShowSeparator(muil,mc);
  493. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_delete");
  494. }
  495. b1=laOnConditionThat(uil,c,laPropExpression(&activeui->PP,0));{
  496. b2=laOnConditionThat(uil,c,laEqual(laPropExpression(&activeui->PP,"type"),laIntExpression(TNS_OBJECT_MESH)));{
  497. muil=laMakeMenuPage(uil,c,"Mesh"); mc=laFirstColumn(muil);{
  498. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_extrude");
  499. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_make");
  500. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_knife");
  501. laShowItemFull(muil,mc,&ui->ExtraPP,"_this_M_knife",0,"mode=loop_cut;text=Loop Cut",0,0);
  502. laShowSeparator(muil,mc);
  503. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_duplicate");
  504. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_merge");
  505. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_separate");
  506. laShowSeparator(muil,mc);
  507. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_subdiv");
  508. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_recalculate_normals");
  509. laShowSeparator(muil,mc);
  510. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_delete");
  511. }
  512. laShowSeparator(uil,c);
  513. laShowItem(uil,c,&ui->ExtraPP,"select_mode")->Flags|=LA_UI_FLAGS_EXPAND;
  514. laShowItem(uil,c,&ui->ExtraPP,"select_through");
  515. }laEndCondition(uil,b2);
  516. b2=laOnConditionThat(uil,c,laEqual(laPropExpression(&activeui->PP,"type"),laIntExpression(TNS_OBJECT_SHAPE)));{
  517. muil=laMakeMenuPage(uil,c,"Shape"); mc=laFirstColumn(muil);{
  518. laShowItem(muil,mc,&ui->ExtraPP,"_this_M_set_point_handle");
  519. laUiItem* b3=laBeginRow(muil,mc,0,0);
  520. laShowItemFull(muil,mc,&ui->ExtraPP,"_this_M_set_shape_closed",0,"text=Open;mode=OPEN",0,0);
  521. laShowItemFull(muil,mc,&ui->ExtraPP,"_this_M_set_shape_closed",0,"text=Close Shape;mode=CLOSE",0,0);
  522. laEndRow(muil,b3);
  523. }
  524. }laEndCondition(uil,b2);
  525. }laEndCondition(uil,b1);
  526. laShowSeparator(uil,c)->Expand=1;
  527. laShowItem(uil,c,&ui->ExtraPP,"display_mode")->Flags|=LA_UI_FLAGS_EXPAND;
  528. laShowItem(uil,c,&ui->ExtraPP,"delta_mode")->Flags|=LA_UI_FLAGS_CYCLE|LA_UI_FLAGS_HIGHLIGHT;
  529. laShowItem(uil,c,&ui->ExtraPP,"show_details")->Flags|=LA_UI_FLAGS_ICON;
  530. laEndRow(uil,b);
  531. b=laOnConditionThat(uil,c,laPropExpression(&ui->ExtraPP,"show_details"));{
  532. laShowColumnAdjuster(uil,c);
  533. g2 = laMakeEmptyGroup(uil, cr, "Info", 0);{
  534. gu2 = g2->Page; gc2 = laFirstColumn(gu2); gu2->HeightCoeff=-1; g2->Flags|=LA_UI_FLAGS_NO_DECAL;
  535. g = laMakeGroup(gu2, gc2, "Scene Info", 0);{ gu = g->Page; gc = laFirstColumn(gu);
  536. laShowLabel(gu, gcl, "Name:", 0, 0);
  537. laShowItem(gu, gc, &ui->PP, "name");
  538. }
  539. g = laMakeGroup(gu2, gc2, "Object", 0);{ gu = g->Page; gc = laFirstColumn(gu);
  540. b1=laOnConditionThat(gu,gc,laPropExpression(&ui->PP,"active"));{
  541. laShowLabel(gu, gc, "Name:", 0, 0);
  542. laShowItem(gu, gc, &ui->PP, "active.name");
  543. b=laOnConditionThat(gu,gc,laPropExpression(&ui->ExtraPP, "delta_mode"));{
  544. laShowLabel(gu, gc, "DLoc:", 0, 0);laShowItem(gu, gc, &ui->PP, "active.dlocation")->Flags|=LA_UI_FLAGS_TRANSPOSE;
  545. laShowSeparator(gu,gc);
  546. laShowLabel(gu, gc, "DRot:", 0, 0);laShowItem(gu, gc, &ui->PP, "active.drotation")->Flags|=LA_UI_FLAGS_TRANSPOSE;
  547. laShowSeparator(gu,gc);
  548. laShowLabel(gu, gc, "DSca:", 0, 0);laShowItem(gu, gc, &ui->PP, "active.dscale")->Flags|=LA_UI_FLAGS_TRANSPOSE;
  549. }laElse(gu,b);{
  550. laShowLabel(gu, gc, "Loc:", 0, 0);laShowItem(gu, gc, &ui->PP, "active.location")->Flags|=LA_UI_FLAGS_TRANSPOSE;
  551. laShowSeparator(gu,gc);
  552. laShowLabel(gu, gc, "Rot:", 0, 0);laShowItem(gu, gc, &ui->PP, "active.rotation")->Flags|=LA_UI_FLAGS_TRANSPOSE;
  553. laShowSeparator(gu,gc);
  554. laShowLabel(gu, gc, "Sca:", 0, 0);laShowItem(gu, gc, &ui->PP, "active.scale")->Flags|=LA_UI_FLAGS_TRANSPOSE;
  555. }laEndCondition(gu,b);
  556. }laElse(gu,b1);{
  557. laShowLabel(gu, gc, "No active object.", 0, 0);
  558. }laEndCondition(gu,b1);
  559. }
  560. }
  561. }laEndCondition(uil,b);
  562. }
  563. void la_3DViewEnsureCamera(laCanvasExtra* e){
  564. if(e->ViewingCamera) return;
  565. tnsVector3d pos={-3, -4, 1.5};
  566. tnsCamera* c= tnsCreateCamera(0, "VIEWING_CAMERA", rad(50), LA_COLOR3(pos), rad(70), 0, rad(-40), 25);
  567. memAssignRef(e,&e->ViewingCamera,c);
  568. tnsVector3d target={0,0,0}; tnsVector3d up={0,0,1};
  569. tnsLookAt(e->ViewingCamera, target, up);
  570. e->ViewingCamera->FocusDistance=tnsDist3dv(pos,target);
  571. }
  572. void la_3DViewInit(laUiItem *ui){
  573. laCanvasExtra *e = ui->Extra;
  574. if (e){ return; }
  575. else{ e = memAcquireHyper(sizeof(laCanvasExtra)); ui->Extra = e; }
  576. la_CanvasInit(ui);
  577. e->ParentUi = ui;
  578. la_3DViewEnsureCamera(e);
  579. e->ShowAxis[0] = 1; e->ShowAxis[1] = 1;
  580. e->ShowFloorGrid = 1;
  581. e->HeightCoeff = 10;
  582. e->ZoomX=1.0f/LA_RH; e->ZoomY=1.0f/LA_RH;
  583. laRecordDifferences(0,"tns.world");
  584. laPushDifferences("Created camera for 3D view widget,",0);
  585. }
  586. void la_3DViewDestroy(laUiItem *ui){
  587. laCanvasExtra *e = ui->Extra;
  588. tnsDelete2DOffscreen(e->OffScr);
  589. tnsDelete2DOffscreen(e->OffScrShadow);
  590. if(e->ViewingCamera) tnsDestroyObject(e->ViewingCamera);
  591. memFree(e);
  592. }
  593. void laDefault2DViewOverlayRight(laUiItem *ui){
  594. laUiList *uil, *gu;
  595. laColumn *c, *cr, *crl, *crr, *gc, *gcl, *gcr, *cl;
  596. laPropPack *e = &ui->ExtraPP;
  597. laUiItem *b, *b1, *b2, *g;
  598. if (!(uil = ui->Subs.pFirst)) uil = laAddTabPage(ui, "New Group");
  599. uil->HeightCoeff=-1;
  600. c = laFirstColumn(uil);
  601. laSplitColumn(uil, c, 0.7);
  602. cl = laLeftColumn(c, 0);
  603. cr = laRightColumn(c, 0);
  604. laShowColumnAdjuster(uil, c);
  605. b=laBeginRow(uil,cl,0,0);
  606. laShowLabel(uil, cl, "Line Width:", 0, 0);
  607. laShowItem(uil, cl, e, "adaptive_line_width")->Flags|=LA_UI_FLAGS_PLAIN;
  608. laEndRow(uil,b);
  609. b=laBeginRow(uil,cl,0,0);
  610. laShowItem(uil, cl, &ui->PP, "size")->Flags|=LA_UI_FLAGS_PLAIN|LA_UI_FLAGS_TRANSPOSE|LA_TEXT_ALIGN_LEFT;
  611. laEndRow(uil,b);
  612. laShowItem(uil, cl, &ui->PP, "internal_type")->Flags|=LA_UI_FLAGS_PLAIN;
  613. g = laMakeFoldableGroup(uil, cr, "Display", 0, 1, 0);{
  614. gu = g->Page;
  615. gc = laFirstColumn(gu);
  616. laSplitColumn(gu, gc, 0.35);
  617. gcl = laLeftColumn(gc, 0);
  618. gcr = laRightColumn(gc, 0);
  619. // needs another mode for access the ExtraPP.
  620. // laShowItem(gu, gc, &ui->ExtraPP, "maximize");
  621. laShowLabel(gu, gcl, "Transparency:", 0, 0);
  622. laShowItem(gu, gcr, e, "draw_image_alpha");
  623. laShowLabel(gu, gcl, "Border:", 0, 0);
  624. laShowItemFull(gu, gcr, e, "draw_image_border", LA_WIDGET_ENUM_CYCLE, 0, 0, 0);
  625. laShowLabel(gu, gcl, "Line Width:", 0, 0);
  626. laShowItemFull(gu, gcr, e, "adaptive_line_width", LA_WIDGET_ENUM_CYCLE, 0, 0, 0);
  627. laShowLabel(gu, gcl, "Cursor:", 0, 0);
  628. laShowItemFull(gu, gcr, e, "draw_cursor", LA_WIDGET_ENUM_CYCLE, 0, 0, 0);
  629. }laEndFoldableGroup(uil,g);
  630. }
  631. void la_CanvasUiInit(laUiItem* ui){ laCanvasTemplate* ct=ui->CanvasTemplate; if(ct->Init) ct->Init(ui); }
  632. void la_CanvasUiDestroy(laUiItem *ui){ laCanvasTemplate* ct=ui->CanvasTemplate; if(ct->Destroy) ct->Destroy(ui); }
  633. void la_CanvasInit(laUiItem *ui){
  634. laCanvasExtra *e = ui->Extra;
  635. if (!e){ e = memAcquireHyper(sizeof(laCanvasExtra)); ui->Extra = e; }
  636. e->ParentUi = ui;
  637. e->HeightCoeff = 10;
  638. e->ZoomX = 1; e->ZoomY = 1;
  639. e->ImageDrawAlpha = 1;
  640. e->ImageDrawBorder = 1;
  641. e->AdaptiveLineWidth = 1;
  642. e->ClearBackground = 1;
  643. laFirstColumn(laAddTabPage(ui, "New Group"));
  644. }
  645. void la_CanvasDestroy(laUiItem *ui){
  646. laCanvasExtra *e = ui->Extra;
  647. tnsDelete2DOffscreen(e->OffScr);
  648. memFree(e);
  649. }
  650. //============================================================= [Operators]
  651. int OPINV_3DOr2DViewUiItem(laOperator *a, laEvent *e){
  652. laUiItem *ui = a->Instance;
  653. a->CustomData = ui->Extra;
  654. return LA_RUNNING;
  655. }
  656. int OPEXT_3DOr2DViewUiItem(laOperator *a, int ExitCode){
  657. return 0;
  658. }
  659. int la_CanvasDetectButtons(laUiItem* ui, laBoxedTheme* bt, int x,int y, int total_buttons, int* very_close){
  660. int midx=(ui->R+ui->L)/2-LA_RH2*(total_buttons-1), midy=ui->B-LA_RH2-bt->BM;
  661. if(y>ui->B-LA_2RH-bt->BM || y<ui->U+LA_2RH+bt->TM || x<ui->L+LA_2RH+bt->TM || x>ui->R-LA_2RH-bt->RM)
  662. { if(very_close)*very_close=1; }else return 0;
  663. if(y<ui->B-LA_RH-bt->BM)return 0;
  664. for(int i=0;i<total_buttons;i++){ if(x>=midx-LA_RH2 && x<midx+LA_RH2) return i+1; midx+=LA_RH;}
  665. return 0;
  666. }
  667. int OPMOD_Canvas(laOperator *a, laEvent *e){
  668. laUiItem *ui = a->Instance;
  669. laBoxedTheme *bt = (*ui->Type->Theme);
  670. laCanvasExtra *ex = a->CustomData;
  671. laUiList *subu;
  672. laUiItem *subui = 0;
  673. laListHandle Locals = {0};
  674. int px = e->x, py = e->y;
  675. if (!laIsInUiItem(ui, e->x, e->y) && !ex->Dragging){
  676. ex->OnX = INT_MAX; ex->OnY = INT_MAX; if(ui->State!=LA_UI_NORMAL){ ui->State=LA_UI_NORMAL; laRedrawCurrentPanel(); }
  677. return LA_FINISHED_PASS;
  678. }
  679. //int x=e->x,y=e->y; laPanel*p=MAIN.CurrentPanel,*dp;
  680. //laLocalToWindow(0, p, &x, &y); if(!p) p=MAIN.CurrentWindow->MaximizedUiPanel;
  681. //if(dp = laDetectPanel(x,y) && dp!=p){ return LA_RUNNING_PASS; }
  682. if(e->type&LA_MOUSE_EVENT){
  683. if(e->type == LA_L_MOUSE_DOWN && ui->Expand>=0 && e->x>ui->R-bt->RM-LA_RH && e->y>ui->B-bt->BM-LA_RH){
  684. ex->Dragging=1; ex->ClickedX=e->x; ex->ClickedY=e->y; ex->TargetIndexVali=ui->Expand;
  685. return LA_RUNNING;
  686. }
  687. if(ex->Dragging==1){
  688. if(e->type==LA_MOUSEMOVE){ ui->Expand=ex->TargetIndexVali+((real)e->y-ex->ClickedY+0.5)/LA_RH;
  689. if(ex->HeightCoeff<1) ex->HeightCoeff=1; laRecalcCurrentPanel(); }
  690. elif(e->type==LA_L_MOUSE_UP){ ex->Dragging=0; }
  691. elif(e->type==LA_R_MOUSE_DOWN){ ex->Dragging=0; ui->Expand=ex->TargetIndexVali; laRecalcCurrentPanel(); }
  692. return LA_RUNNING;
  693. }
  694. int VeryClose=0; int btn=la_CanvasDetectButtons(ui, bt, e->x, e->y, 2, &VeryClose);
  695. if(e->type==LA_L_MOUSE_DOWN){
  696. if(btn==2){ if(MAIN.CurrentWindow->MaximizedUi==ui) laRestoreCanvasUI(); else laMaximizeCanvasUI(ui,MAIN.CurrentPanel); return LA_RUNNING; }
  697. if(btn==1){
  698. if(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)ui->Flags&=~LA_UI_FLAGS_NO_OVERLAY; else ui->Flags|=LA_UI_FLAGS_NO_OVERLAY;
  699. laRedrawCurrentPanel(); return LA_RUNNING;
  700. }
  701. }
  702. int state=VeryClose?(btn?LA_UI_EDITING:LA_UI_ACTIVE):LA_UI_NORMAL;
  703. if(state!=ui->State){ ui->State=state; laRedrawCurrentPanel(); }
  704. }
  705. if(!(ui->Flags&LA_UI_FLAGS_NO_OVERLAY)){
  706. for (subu = ui->Subs.pFirst; subu; subu = subu->Item.pNext){
  707. if (subui = la_DetectUiItemRecursive(subu, px, py, ui->B, &Locals, 0)){
  708. if (subui && !a->Child && subui->Type->OperatorType){
  709. laUiList *luil = ((laUiListDrawItem *)Locals.pFirst)->Target;
  710. laSetOperatorLocalizer(a->ToPanel);
  711. if(subui && !a->Child && subui->Type->OperatorType && !la_UiOperatorExists(subui)){
  712. if (laInvokeUiP(a, subui->Type->OperatorType, e, subui, &Locals, 0) >= 0); laRetriggerOperators();
  713. }
  714. lstClearPointer(&Locals);
  715. return LA_RUNNING_PASS;
  716. }
  717. }
  718. lstClearPointer(&Locals);
  719. if(e->type&LA_KEY_MOUSE_SCROLL){
  720. laUiItem *pui = 0; laListHandle levels={0}; int dir=(e->type&LA_STATE_DOWN)?1:-1;
  721. laUiList *duil = la_DetectUiListRecursiveDeep(subu, e->x, e->y, 10000, &pui, 0, 0, 0, 0, &levels);
  722. laUiListRecord* lip=levels.pLast; laUiList* uuil=lip->uil; laUiItem* upui=lip->Item.pPrev?((laUiListRecord*)lip->Item.pPrev)->pui:0; int ran=0;
  723. while (lip && upui){
  724. if((ran=laPanUiListAuto(uuil, 0, dir*MAIN.ScrollingSpeed*LA_RH,
  725. uuil->L, upui->R-(uuil->ScrollerShownV?(LA_SCROLL_W+bt->RM):0),
  726. uuil->U, upui->B-(*upui->Type->Theme)->BM-(uuil->ScrollerShownH?(LA_SCROLL_W+bt->BM):0)))) break;
  727. lip=lip->Item.pPrev; uuil=lip->uil; upui=lip->Item.pPrev?((laUiListRecord*)lip->Item.pPrev)->pui:0;
  728. }
  729. if(ran)laRedrawCurrentPanel();
  730. if(ran){return LA_RUNNING;}
  731. }
  732. }
  733. }
  734. if (ex->DrawCursor){
  735. ex->OnX = e->x;
  736. ex->OnY = e->y;
  737. laRedrawCurrentPanel();
  738. }
  739. if(ui->CanvasTemplate->ExtraModal){ if(!(ui->CanvasTemplate->ExtraModal(a,e)&LA_PASS_ON)) return LA_RUNNING; }
  740. if(!ex->AsPlayer){
  741. if (laKeyMapExecuteEventEx(a, &ui->ExtraPP, &ui->CanvasTemplate->KeyMapper, e)) return LA_RUNNING;
  742. if (laKeyMapExecuteEventEx(a, &ui->ExtraPP, &ui->Type->KeyMapper, e)) return LA_RUNNING;
  743. }
  744. return LA_RUNNING_PASS;
  745. }
  746. int OPCHK_Is2DViewExtra(laPropPack *This, laStringSplitor *ss){
  747. return 1;
  748. //if (This && (This->LastPs->p->SubProp == _LA_PROP_2D_EXTRA)) return 1;
  749. return 0;
  750. }
  751. int OPINV_CanvasZoom(laOperator *a, laEvent *e){
  752. laCanvasExtra *ex = a->This->EndInstance;
  753. if (strArgumentMatch(a->ExtraInstructionsP, "mode", "mouse")){
  754. laGeneralUiExtraData *ex = memAcquireSimple(sizeof(laGeneralUiExtraData));
  755. laSetWindowCursor(LA_HAND);
  756. a->CustomData = ex;
  757. ex->LastX = e->x;
  758. ex->LastY = e->y;
  759. return LA_RUNNING;
  760. }
  761. if (strArgumentMatch(a->ExtraInstructionsP, "direction", "in")){
  762. if (strArgumentMatch(a->ExtraInstructionsP, "axis", "x")){
  763. ex->ZoomX *= 0.9;
  764. }else{
  765. ex->ZoomX *= 0.9;
  766. ex->ZoomY *= 0.9;
  767. }
  768. laRedrawCurrentPanel();
  769. }elif (strArgumentMatch(a->ExtraInstructionsP, "direction", "out")){
  770. if (strArgumentMatch(a->ExtraInstructionsP, "axis", "x")){
  771. ex->ZoomX *= 1.1;
  772. }else{
  773. ex->ZoomX *= 1.1;
  774. ex->ZoomY *= 1.1;
  775. }
  776. laRedrawCurrentPanel();
  777. }
  778. return LA_FINISHED;
  779. }
  780. int OPMOD_CanvasZoom(laOperator *a, laEvent *e){
  781. laCanvasExtra *ex = a->This->EndInstance;
  782. laGeneralUiExtraData *uex = a->CustomData;
  783. if (e->type == LA_L_MOUSE_UP || e->type == LA_R_MOUSE_DOWN || e->type==LA_M_MOUSE_UP){
  784. laSetWindowCursor(LA_ARROW);
  785. return LA_FINISHED;
  786. }
  787. if (e->type == LA_MOUSEMOVE){
  788. if (strArgumentMatch(a->ExtraInstructionsP, "axis", "x")){
  789. ex->ZoomX *= (1.0 - (e->x - uex->LastX) * MAIN.ZoomSpeed2D);
  790. }elif(strArgumentMatch(a->ExtraInstructionsP, "lock", "true")){
  791. ex->ZoomX *= (1.0 - (e->y - uex->LastY) * MAIN.ZoomSpeed2D); ex->ZoomY = ex->ZoomX;
  792. }else{
  793. ex->ZoomX *= (1.0 - (e->x - uex->LastX) * MAIN.ZoomSpeed2D);
  794. ex->ZoomY *= (1.0 + (e->y - uex->LastY) * MAIN.ZoomSpeed2D);
  795. }
  796. if(ex->ZoomX<0||ex->ZoomX!=ex->ZoomX){
  797. printf("Error zoom!\n"); ex->ZoomX=1; ex->ZoomY=1;
  798. }
  799. uex->LastX = e->x;
  800. uex->LastY = e->y;
  801. laRedrawCurrentPanel();
  802. }
  803. return LA_RUNNING;
  804. }
  805. int OPMOD_CanvasMove(laOperator *a, laEvent *e){
  806. laCanvasExtra *ex = a->This->EndInstance;
  807. laGeneralUiExtraData *uex = a->CustomData;
  808. if (e->type == LA_L_MOUSE_UP || e->type == LA_R_MOUSE_DOWN || e->type==LA_M_MOUSE_UP ||
  809. (e->type==LA_KEY_UP && e->key==' ')) {
  810. laSetWindowCursor(LA_ARROW);
  811. return LA_FINISHED;
  812. }
  813. if (e->type == LA_MOUSEMOVE){
  814. if (strArgumentMatch(a->ExtraInstructionsP, "axis", "x")){
  815. ex->PanX -= (e->x - uex->LastX) * ex->ZoomX;
  816. }else{
  817. ex->PanX -= (e->x - uex->LastX) * ex->ZoomX;
  818. ex->PanY += (e->y - uex->LastY) * ex->ZoomY;
  819. }
  820. uex->LastX = e->x;
  821. uex->LastY = e->y;
  822. laRedrawCurrentPanel();
  823. }
  824. return LA_RUNNING;
  825. }
  826. int OPINV_CanvasClick(laOperator *a, laEvent *e){
  827. laCanvasExtra *ex = a->This->EndInstance;
  828. laGeneralUiExtraData *uex = a->CustomData;
  829. if (e->type == LA_L_MOUSE_DOWN){
  830. ex->ClickedX = (e->x - (ex->ParentUi->R - ex->ParentUi->L) / 2 - ex->ParentUi->L) * ex->ZoomX + ex->PanX;
  831. ex->ClickedY = ((ex->ParentUi->B - ex->ParentUi->U) / 2 - e->y + ex->ParentUi->U) * ex->ZoomY + ex->PanY;
  832. laRedrawCurrentPanel();
  833. }
  834. return LA_FINISHED_PASS;
  835. }
  836. int OPCHK_Is3DViewExtra(laPropPack *This, laStringSplitor *ss){
  837. if (This && This->LastPs->p->SubProp == _LA_PROP_3D_EXTRA) return 1;
  838. return 0;
  839. }
  840. int OPINV_3DViewCameraZoom(laOperator *a, laEvent *e){
  841. laCanvasExtra *ex = a->This->EndInstance;
  842. tnsCamera *c = ex->ViewingCamera;
  843. laUiItem* ui=ex->ParentUi; tnsRootObject* root=ui->PP.EndInstance;
  844. if(root && root->Base.Type==TNS_OBJECT_ROOT && root->Is2D){
  845. return OPINV_CanvasZoom(a,e);
  846. }
  847. if (strArgumentMatch(a->ExtraInstructionsP, "direction", "in")){
  848. tnsZoomViewingCamera(c, 0.1);
  849. laRedrawCurrentPanel();
  850. }elif (strArgumentMatch(a->ExtraInstructionsP, "direction", "out")){
  851. tnsZoomViewingCamera(c, -0.1);
  852. laRedrawCurrentPanel();
  853. }
  854. return LA_FINISHED;
  855. }
  856. int OPINV_3DOr2DViewAdjust(laOperator *a, laEvent *e){
  857. laGeneralUiExtraData *ex = memAcquireSimple(sizeof(laGeneralUiExtraData));
  858. laSetWindowCursor(LA_HAND);
  859. a->CustomData = ex;
  860. ex->LastX = e->x; ex->LastY = e->y;
  861. return LA_RUNNING;
  862. }
  863. int OPEXT_3DOr2DViewAdjust(laOperator *a, int Mark){
  864. if (a->CustomData) memFree(a->CustomData);
  865. laSetWindowCursor(LA_ARROW);
  866. }
  867. int OPMOD_3DViewCameraRotate(laOperator *a, laEvent *e){
  868. laCanvasExtra *ex = a->This->EndInstance;
  869. laGeneralUiExtraData *uex = a->CustomData;
  870. laUiItem* ui=ex->ParentUi; tnsRootObject* root=ui->PP.EndInstance;
  871. if(root && root->Base.Type==TNS_OBJECT_ROOT && root->Is2D){
  872. return OPMOD_CanvasMove(a,e);
  873. }
  874. if (e->type == LA_L_MOUSE_UP || e->type == LA_M_MOUSE_UP || e->type == LA_R_MOUSE_DOWN) return LA_FINISHED;
  875. if (e->type == LA_MOUSEMOVE){
  876. tnsRotateViewingCamera(ex->ViewingCamera, (real)(uex->LastY - e->y) / 150.0, (real)(uex->LastX - e->x) / 150.0);
  877. uex->LastX = e->x;
  878. uex->LastY = e->y;
  879. laRedrawCurrentPanel();
  880. }
  881. return LA_RUNNING;
  882. }
  883. int OPMOD_3DViewCameraMove(laOperator *a, laEvent *e){
  884. laCanvasExtra *ex = a->This->EndInstance;
  885. laGeneralUiExtraData *uex = a->CustomData;
  886. laUiItem* ui=ex->ParentUi; tnsRootObject* root=ui->PP.EndInstance;
  887. if(root && root->Base.Type==TNS_OBJECT_ROOT && root->Is2D){
  888. return OPMOD_CanvasMove(a,e);
  889. }
  890. if (e->type == LA_L_MOUSE_UP || e->type == LA_M_MOUSE_UP || e->type == LA_R_MOUSE_DOWN){
  891. laSetWindowCursor(LA_ARROW);
  892. return LA_FINISHED;
  893. }
  894. if (e->type == LA_MOUSEMOVE){
  895. tnsTranslateViewingCamera(ex->ViewingCamera, ex->ParentUi->R - ex->ParentUi->L, ex->ParentUi->B - ex->ParentUi->U, -e->x + uex->LastX, e->y - uex->LastY);
  896. uex->LastX = e->x; uex->LastY = e->y;
  897. laRedrawCurrentPanel();
  898. }
  899. return LA_RUNNING;
  900. }
  901. void la_RegisterViewerOperators(){
  902. laCreateOperatorType("LA_canvas_operator", "2D View UiItem Operator", "All Visual 2D View Operations Are Called From This Ui",
  903. 0, 0, OPEXT_3DOr2DViewUiItem, OPINV_3DOr2DViewUiItem, OPMOD_Canvas, U'🖦', LA_EXTRA_TO_PANEL | LA_ACTUATOR_SYSTEM | LA_ACTUATOR_HIDDEN);
  904. laCreateOperatorType("LA_3d_view_camera_zoom", "Camera Zoom", "Let View Camera Zoom In Or Out",
  905. OPCHK_Is3DViewExtra, 0, 0, OPINV_3DViewCameraZoom, 0, U'🔎', 0);
  906. laCreateOperatorType("LA_3d_view_camera_rotate", "Camera Rotate", "Let View Camera Rotate Along Local X/Y Axis",
  907. OPCHK_Is3DViewExtra, 0, OPEXT_3DOr2DViewAdjust, OPINV_3DOr2DViewAdjust, OPMOD_3DViewCameraRotate, U'🗘', LA_EXTRA_TO_PANEL);
  908. laCreateOperatorType("LA_3d_view_camera_move", "Camera Move", "Let View Camera Move Along Local X/Y Axis",
  909. OPCHK_Is3DViewExtra, 0, OPEXT_3DOr2DViewAdjust, OPINV_3DOr2DViewAdjust, OPMOD_3DViewCameraMove, U'🤚', LA_EXTRA_TO_PANEL);
  910. laCreateOperatorType("LA_2d_view_zoom", "2D Zoom", "Let View 2D Cavans Zoom In Or Out",
  911. OPCHK_Is2DViewExtra, 0, OPEXT_3DOr2DViewAdjust, OPINV_CanvasZoom, OPMOD_CanvasZoom, U'🔎', 0);
  912. laCreateOperatorType("LA_2d_view_move", "2D Move", "Let View 2D Cavans Move Along Local X/Y Axis",
  913. OPCHK_Is2DViewExtra, 0, OPEXT_3DOr2DViewAdjust, OPINV_3DOr2DViewAdjust, OPMOD_CanvasMove, U'🤚', LA_EXTRA_TO_PANEL);
  914. laCreateOperatorType("LA_2d_view_click", "2D Click", "2D Click",
  915. OPCHK_Is2DViewExtra, 0, OPEXT_3DOr2DViewAdjust, OPINV_CanvasClick, 0, U'🖦', LA_EXTRA_TO_PANEL);
  916. }
  917. void *tnsget_detached_FirstScene(void *UNUSED1, void *UNUSED2);
  918. void laset_CanvasSelectMode(laCanvasExtra* ex, int mode){
  919. ex->SelectMode=mode; laUiItem* ui=ex->ParentUi;
  920. tnsObject*root=ui?ui->PP.EndInstance:0; if(!root) return;
  921. if(root->Active){ if(root->Active->Type==TNS_OBJECT_MESH && ((tnsMeshObject*)root->Active)->Mode==TNS_MESH_EDIT_MODE){ tnsMMeshEnsureSelection(root->Active, mode); } }
  922. }
  923. void la_RegisterUiTypesViewerWidgets(){
  924. laPropContainer *pc = 0;
  925. laProp *p = 0;
  926. laKeyMapper *km;
  927. _LA_UI_CANVAS = la_RegisterUiType("LA_canvas_default", 0, "LA_canvas_operator", &_LA_THEME_2D_VIEW, la_CanvasDraw, la_CanvasGetHeight, la_CanvasUiInit, la_CanvasUiDestroy);
  928. _LA_UI_CANVAS->Tag = LA_UI_TAG_NEED_REBUILD;
  929. laCanvasTemplate* ct=laRegisterCanvasTemplate("la_CanvasDrawTexture", "tns_texture", 0, la_CanvasDrawTexture, la_CanvasDrawOverlay, la_CanvasInit, la_CanvasDestroy);
  930. pc = laCanvasHasExtraProps(ct,sizeof(laCanvasExtra),2);{
  931. _LA_PROP_2D_EXTRA = pc;
  932. laAddIntProperty(pc, "height_coeff", "Ui Height", "Ui Height Coefficiency Entry", 0, 0, "Rows", 100, -100, 1, 0, 0, offsetof(laCanvasExtra, HeightCoeff), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  933. p = laAddEnumProperty(pc, "draw_image_alpha", "Draw Image Alpha", "Draw grid background on alpha<1", 0, 0, 0, 0, 0,
  934. offsetof(laCanvasExtra, ImageDrawAlpha), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);{
  935. laAddEnumItem(p, "null", "null", "Don't Draw Grid", 0);
  936. laAddEnumItem(p, "normal", "normal", "Use Normal Color", 0);
  937. laAddEnumItem(p, "bright", "bright", "Draw Alpha Grid Using Very Bright White Color", 0);
  938. }
  939. p = laAddEnumProperty(pc, "draw_image_border", "Draw Image Border", "Draw image border using same color as ui item", 0, 0, 0, 0, 0,
  940. offsetof(laCanvasExtra, ImageDrawBorder), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);{
  941. laAddEnumItem(p, "no", "No", "Don't Draw Border", U'☐');
  942. laAddEnumItem(p, "yes", "Yes", "Draw Border", U'☑');
  943. }
  944. p = laAddEnumProperty(pc, "adaptive_line_width", "Adaptive Line Width", "glLineWidth() will follow 2dview zooming", 0, 0, 0, 0, 0,
  945. offsetof(laCanvasExtra, AdaptiveLineWidth), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);{
  946. laAddEnumItem(p, "constant", "Constant", "Don't change line width", U'☐');
  947. laAddEnumItem(p, "adaptive", "Adaptive", "Adaptive Line Width", U'☑');
  948. }
  949. p = laAddEnumProperty(pc, "line_width_warning", "Line Width Warnning", "Show whether line width is acceptable by hardware", 0, 0, 0, 0, 0,
  950. offsetof(laCanvasExtra, LineWidthWarning), 0, 0, 0, 0, 0, 0, 0, 0, 0, LA_READ_ONLY);{
  951. laAddEnumItem(p, "acceptable", "Acceptable", "Line width is acceptable by graphic hadware", U'✔');
  952. laAddEnumItem(p, "too_wide", "Too Wide", "Line width is too wide for graphic hadware", U'🞫');
  953. laAddEnumItem(p, "too_thin", "Too Thin", "Line width is too thin for graphic hadware", U'🞫');
  954. }
  955. p = laAddEnumProperty(pc, "clear_background", "Clear Background", "Clear background", 0, 0, 0, 0, 0, offsetof(laCanvasExtra, ClearBackground), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);{
  956. laAddEnumItem(p, "no", "No", "Don't Clear Background", U'🌔');
  957. laAddEnumItem(p, "yes", "Yes", "Clear Background", U'🌑');
  958. }
  959. p = laAddEnumProperty(pc, "draw_cursor", "Show Cursor", "Show cursor", 0, 0, 0, 0, 0, offsetof(laCanvasExtra, DrawCursor), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);{
  960. laAddEnumItem(p, "no", "No", "Don't draw cursor", U'🖦');
  961. laAddEnumItem(p, "yes", "Yes", "Draw cursor", U'➕');
  962. }
  963. laAddFloatProperty(pc, "pan", "Pan", "Pan On X,Y Axis", 0, "X,Y", "px", 0, 0, 1, 0, 0, offsetof(laCanvasExtra, PanX), 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0);
  964. laAddFloatProperty(pc, "zoom", "Zoom", "Zoom Factor On X,Y Axis", 0, "X,Y", 0, 0, 0, 0.01, 1, 0, offsetof(laCanvasExtra, ZoomX), 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0);
  965. //laAddSubGroup(pc, "Template", "Template Used To Draw 2D Stuff", "la_2d_view_template",0, 0, 0, -offsetof(laCanvasExtra, Template), 0, 0, 0, 0, 0, 0, 0, 0, LA_UDF_REFER);
  966. laAddOperatorProperty(pc, "zoom", "Zoom", "Zoom 2D Canvans", "LA_2d_view_zoom", U'🔎', 0);
  967. laAddOperatorProperty(pc, "move", "Move", "Move 2D Canvans", "LA_2d_view_move", U'🤚', 0);
  968. laAddOperatorProperty(pc, "click", "Click", "Click On 2D Canvans", "LA_2d_view_click", U'🤚', 0);
  969. laAddSubGroup(pc, "parent_ui", "Parent UI", "The Ui That Holds The Viewer", "ui_item",0, 0, 0, offsetof(laCanvasExtra, ParentUi), 0, 0, 0, 0, 0, 0, 0, LA_UDF_REFER);
  970. }
  971. km = &ct->KeyMapper;
  972. laAssignNewKey(km, 0, "LA_2d_view_zoom", LA_KM_SEL_UI_EXTRA, 0, LA_MOUSE_WHEEL_DOWN, 0, "direction=out");
  973. laAssignNewKey(km, 0, "LA_2d_view_zoom", LA_KM_SEL_UI_EXTRA, 0, LA_MOUSE_WHEEL_UP, 0, "direction=in");
  974. laAssignNewKey(km, 0, "LA_2d_view_move", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT, LA_L_MOUSE_DOWN, 0, 0);
  975. laAssignNewKey(km, 0, "LA_2d_view_click", LA_KM_SEL_UI_EXTRA, 0, LA_L_MOUSE_DOWN, 0, 0);
  976. ct=laRegisterCanvasTemplate("la_3DView", "tns_object", 0, la_RootObjectDraw, la_RootObjectDrawOverlay, la_3DViewInit, la_3DViewDestroy);
  977. pc = laCanvasHasExtraProps(ct, sizeof(laCanvasExtra), 2);{
  978. _LA_PROP_3D_EXTRA = pc;
  979. p = laAddEnumProperty(pc, "show_axis", "Show Axis", "Show Global X,Y,Z Axis", LA_WIDGET_ENUM_CYCLE, "X,Y,z", 0, 0, 0, offsetof(laCanvasExtra, ShowAxis), 0, 0, 3, 0, 0, 0, 0, 0, 0, 0);{
  980. laAddEnumItem(p, "HIDDEN", "Hidden", "Current Axis Is Hidden", U'🌔');
  981. laAddEnumItem(p, "SHOWN", "Shown", "Current Axis Is Shown", U'🌑');
  982. }
  983. p = laAddEnumProperty(pc, "show_floor_grid", "Show Floor Grid", "Show floor grid", 0, 0, 0, 0, 0, offsetof(laCanvasExtra, ShowFloorGrid), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);{
  984. laAddEnumItem(p, "HIDDEN", "Hidden", "Current Axis Is Hidden", U'🌔');
  985. laAddEnumItem(p, "SHOWN", "Shown", "Current Axis Is Shown", U'🌑');
  986. }
  987. p = laAddEnumProperty(pc, "select_mode", "Select Mode", "Select by vertices or edges", 0, 0, 0, 0, 0, offsetof(laCanvasExtra, SelectMode), 0, laset_CanvasSelectMode, 0, 0, 0, 0, 0, 0, 0, 0);{
  988. laAddEnumItemAs(p, "VERTS", "Verts", "Select by vertices", LA_CANVAS_SELECT_MODE_VERTS,0);
  989. laAddEnumItemAs(p, "EDGES", "Edges", "Select by edges", LA_CANVAS_SELECT_MODE_EDGES,0);
  990. }
  991. p = laAddEnumProperty(pc, "select_through", "Select Through", "Select through stuff", LA_WIDGET_ENUM_HIGHLIGHT, 0, 0, 0, 0, offsetof(laCanvasExtra, SelectThrough), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);{
  992. laAddEnumItemAs(p, "OFF", "Off", "Don't select through stuff", LA_CANVAS_SELECT_THROUGH_OFF,0);
  993. laAddEnumItemAs(p, "ON", "On", "Select through stuff", LA_CANVAS_SELECT_THROUGH_ON,0);
  994. }
  995. p = laAddEnumProperty(pc, "delta_mode", "Delta Mode", "Toggle delta transformation mode for animation editing", 0, 0, 0, 0, 0, offsetof(laCanvasExtra, DeltaMode), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);{
  996. laAddEnumItemAs(p, "NONE", "None", "Regular mode",0,0);
  997. laAddEnumItemAs(p, "DELTA", "Delta", "Delta mode",1,0);
  998. }
  999. p = laAddEnumProperty(pc, "show_details", "Show Details", "Show detailed information", LA_WIDGET_ENUM_HIGHLIGHT, 0, 0, 0, 0, offsetof(laCanvasExtra, ShowDetails), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);{
  1000. laAddEnumItem(p, "HIDDEN", "Hidden", "Current Axis Is Hidden", U'🛈');
  1001. laAddEnumItem(p, "SHOWN", "Shown", "Current Axis Is Shown", U'i');
  1002. }
  1003. p = laAddEnumProperty(pc, "display_mode", "Display Mode", "Display mode of the viewport", 0, 0, 0, 0, 0, offsetof(laCanvasExtra, DisplayMode), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);{
  1004. laAddEnumItemAs(p, "SOLID", "Solid", "Solid object view",LA_CANVAS_DISPLAY_SOLID, 0);
  1005. laAddEnumItemAs(p, "MATERIAL", "Material", "Material view",LA_CANVAS_DISPLAY_MATERIAL, 0);
  1006. }
  1007. laAddIntProperty(pc, "height_coeff", "Ui Height", "Ui Height Coefficiency Entry", 0, 0, "Rows", 100, -100, 1, 0, 0, offsetof(laCanvasExtra, HeightCoeff), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  1008. laAddOperatorProperty(pc, "zoom", "Zoom", "Zoom Viewing Camera", "LA_3d_view_camera_zoom", U'🔎', 0);
  1009. laAddOperatorProperty(pc, "rotate", "Rotate", "Rotate Viewing Camera", "LA_3d_view_camera_rotate", U'🗘', 0);
  1010. laAddOperatorProperty(pc, "move", "Move", "Move Viewing Camera", "LA_3d_view_camera_move", U'🤚', 0);
  1011. //laAddSubGroup(pc, "Viewing Camera", "Unique Camera That Is Used To Draw 3D Viewport", "tns_object",0, 0, 0, -offsetof(laCanvasExtra, ViewingCamera), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  1012. laAddSubGroup(pc, "parent_ui", "Parent Ui", "Parent Ui (Mostly Used To Determin Viewport Size)", "ui_item",0, 0, 0, offsetof(laCanvasExtra, ParentUi), 0, 0, 0, 0, 0, 0, 0, LA_UDF_REFER);
  1013. laAddOperatorProperty(pc, "align_camera_to_view", "Align Active Camera To View", "Align Active Camera To View", "TNS_align_camera_to_view", U'🎥', 0);
  1014. laAddOperatorProperty(pc, "align_view_to_camera", "Align View To Active Camera", "Align View To Active Camera", "TNS_align_view_to_camera", U'🎥', 0);
  1015. laAddOperatorProperty(pc, "_this_M_delete", "Delete", "Delete parts of mesh", "M_delete", 0, 0);
  1016. laAddOperatorProperty(pc, "_this_M_make_parent", "Make parent", "Parent objects to active objects or unparent selected ones", "M_make_parent", 0, 0);
  1017. laAddOperatorProperty(pc, "_this_M_unparent", "Unparent", "Unparent selected objects", "M_unparent", 0, 0);
  1018. laAddOperatorProperty(pc, "_this_M_add", "Add", "Add objects/primitives", "M_add", 0, 0);
  1019. laAddOperatorProperty(pc, "_this_M_grab", "Grab", "Grab things and move around", "M_grab", 0, 0);
  1020. laAddOperatorProperty(pc, "_this_M_scale", "Scale", "Scale selected things", "M_scale", 0, 0);
  1021. laAddOperatorProperty(pc, "_this_M_rotate", "Rotate", "Rotation selected things", "M_rotate", 0, 0);
  1022. laAddOperatorProperty(pc, "_this_M_extrude", "Extrude", "Extrude parts of the mesh", "M_extrude", 0, 0);
  1023. laAddOperatorProperty(pc, "_this_M_delete", "Delete", "Delete parts of the mesh", "M_delete", 0, 0);
  1024. laAddOperatorProperty(pc, "_this_M_make", "Make", "Make mesh primitive from selected ones", "M_make", 0, 0);
  1025. laAddOperatorProperty(pc, "_this_M_subdiv", "Subdiv", "Subdivide edges", "M_subdiv", 0, 0);
  1026. laAddOperatorProperty(pc, "_this_M_add", "Add", "Add objects/primitives", "M_add", 0, 0);
  1027. laAddOperatorProperty(pc, "_this_M_separate", "Separate", "Separate mesh parts", "M_separate", 0, 0);
  1028. laAddOperatorProperty(pc, "_this_M_combine", "Combine", "Combine mesh objects", "M_combine", 0, 0);
  1029. laAddOperatorProperty(pc, "_this_M_duplicate", "Duplicate", "Duplicate objects", "M_duplicate", 0, 0);
  1030. laAddOperatorProperty(pc, "_this_M_recalculate_normals", "Recalculate Normals", "Recalculate normals", "M_recalculate_normals", 0, 0);
  1031. laAddOperatorProperty(pc, "_this_M_knife", "Knife", "Cut though edges", "M_knife", 0, 0);
  1032. laAddOperatorProperty(pc, "_this_M_merge", "Merge", "Merge vertices", "M_merge", 0, 0);
  1033. laAddOperatorProperty(pc, "_this_M_clear_transformations", "Clear Transformations", "Clear object transformations", "M_clear_transformations", 0, 0);
  1034. laAddOperatorProperty(pc, "_this_M_set_point_handle", "Set Point Handle", "Set handle type of selected points", "M_set_point_handle", 0, 0);
  1035. laAddOperatorProperty(pc, "_this_M_set_shape_closed", "Set Shape Closed", "Open or close the shape", "M_set_shape_closed", 0, 0);
  1036. }
  1037. km = &ct->KeyMapper;
  1038. laAssignNewKey(km, 0, "LA_3d_view_camera_zoom", LA_KM_SEL_UI_EXTRA, 0, LA_MOUSE_WHEEL_DOWN, 0, "direction=out");
  1039. laAssignNewKey(km, 0, "LA_3d_view_camera_zoom", LA_KM_SEL_UI_EXTRA, 0, LA_MOUSE_WHEEL_UP, 0, "direction=in");
  1040. laAssignNewKey(km, 0, "LA_3d_view_camera_rotate", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT, LA_L_MOUSE_DOWN, 0, 0);
  1041. laAssignNewKey(km, 0, "LA_3d_view_camera_rotate", LA_KM_SEL_UI_EXTRA, 0, LA_M_MOUSE_DOWN, 0, 0);
  1042. laAssignNewKey(km, 0, "LA_3d_view_camera_move", LA_KM_SEL_UI_EXTRA, LA_KEY_SHIFT, LA_M_MOUSE_DOWN, 0, 0);
  1043. laAssignNewKey(km, 0, "LA_3d_view_camera_move", LA_KM_SEL_UI_EXTRA, LA_KEY_SHIFT | LA_KEY_ALT, LA_L_MOUSE_DOWN, 0, 0);
  1044. //laAssignNewKey(km, 0, "TNS_align_camera_to_view", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT | LA_KEY_SHIFT, LA_R_MOUSE_DOWN, 0, 0);
  1045. //laAssignNewKey(km, 0, "TNS_align_view_to_camera", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, '0', 0);
  1046. laAssignNewKey(km, 0, "M_set_cursor", LA_KM_SEL_UI_EXTRA, 0, LA_L_MOUSE_DOWN, 0, 0);
  1047. laAssignNewKey(km, 0, "M_toggle_edit_mode", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, LA_KEY_TAB, 0);
  1048. laAssignNewKey(km, 0, "M_select", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT, LA_R_MOUSE_DOWN, 0, 0);
  1049. laAssignNewKey(km, 0, "M_select", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT|LA_KEY_CTRL, LA_R_MOUSE_DOWN, 0, 0);
  1050. laAssignNewKey(km, 0, "M_select", LA_KM_SEL_UI_EXTRA, LA_KEY_SHIFT, LA_R_MOUSE_DOWN, 0, 0);
  1051. laAssignNewKey(km, 0, "M_select", LA_KM_SEL_UI_EXTRA, LA_KEY_SHIFT|LA_KEY_ALT, LA_R_MOUSE_DOWN, 0, 0);
  1052. laAssignNewKey(km, 0, "M_select", LA_KM_SEL_UI_EXTRA, LA_KEY_SHIFT|LA_KEY_ALT|LA_KEY_CTRL, LA_R_MOUSE_DOWN, 0, 0);
  1053. laAssignNewKey(km, 0, "M_select", LA_KM_SEL_UI_EXTRA, 0, LA_R_MOUSE_DOWN, 0, 0);
  1054. laAssignNewKey(km, 0, "M_select", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'b', "mode=box;");
  1055. laAssignNewKey(km, 0, "M_select", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'a', "mode=toggle;");
  1056. laAssignNewKey(km, 0, "M_grab", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'g', 0);
  1057. laAssignNewKey(km, 0, "M_scale", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 's', 0);
  1058. laAssignNewKey(km, 0, "M_rotate", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'r', 0);
  1059. laAssignNewKey(km, 0, "M_clear_transformations", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT, LA_KEY_DOWN, 'g', "channel=loc");
  1060. laAssignNewKey(km, 0, "M_clear_transformations", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT, LA_KEY_DOWN, 's', "channel=sca");
  1061. laAssignNewKey(km, 0, "M_clear_transformations", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT, LA_KEY_DOWN, 'r', "channel=rot");
  1062. laAssignNewKey(km, 0, "M_clear_transformations", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT, LA_KEY_DOWN, 't', 0);
  1063. laAssignNewKey(km, 0, "M_make_parent", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'p', 0);
  1064. laAssignNewKey(km, 0, "M_unparent", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT, LA_KEY_DOWN, 'p', 0);
  1065. laAssignNewKey(km, 0, "M_extrude", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'e', 0);
  1066. laAssignNewKey(km, 0, "M_extrude", LA_KM_SEL_UI_EXTRA, LA_KEY_SHIFT, LA_KEY_DOWN, 'd', "duplicate_only=true;text=Duplicate;");
  1067. laAssignNewKey(km, 0, "M_delete", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'x', 0);
  1068. laAssignNewKey(km, 0, "M_make", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'f', 0);
  1069. laAssignNewKey(km, 0, "M_subdiv", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'w', 0);
  1070. laAssignNewKey(km, 0, "M_add", LA_KM_SEL_UI_EXTRA, LA_KEY_SHIFT, LA_KEY_DOWN, 'a', 0);
  1071. laAssignNewKey(km, 0, "M_separate", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'p', 0);
  1072. laAssignNewKey(km, 0, "M_combine", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'j', 0);
  1073. laAssignNewKey(km, 0, "M_duplicate", LA_KM_SEL_UI_EXTRA, LA_KEY_SHIFT, LA_KEY_DOWN, 'd', 0);
  1074. laAssignNewKey(km, 0, "M_recalculate_normals", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'n', 0);
  1075. laAssignNewKey(km, 0, "M_knife", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'k', 0);
  1076. laAssignNewKey(km, 0, "M_knife", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'r', "mode=loop_cut");
  1077. laAssignNewKey(km, 0, "M_merge", LA_KM_SEL_UI_EXTRA, LA_KEY_ALT, LA_KEY_DOWN, 'm', 0);
  1078. laAssignNewKey(km, 0, "M_select_linked", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'l', 0);
  1079. laAssignNewKey(km, 0, "M_set_point_handle", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'v', 0);
  1080. laAssignNewKey(km, 0, "M_set_shape_closed", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'q', 0);
  1081. laAssignNewKey(km, 0, "M_set_shape_closed", LA_KM_SEL_UI_EXTRA, LA_KEY_SHIFT, LA_KEY_DOWN, 'q', "reset=TRUE");
  1082. laAssignNewKey(km, 0, "M_set_shape_hole", LA_KM_SEL_UI_EXTRA, 0, LA_KEY_DOWN, 'n', 0);
  1083. laAssignNewKey(km, 0, "M_reorder_shape", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, LA_KEY_ARRDOWN, "direction=DOWN");
  1084. laAssignNewKey(km, 0, "M_reorder_shape", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, LA_KEY_ARRUP, "direction=UP");
  1085. }