*/}}

la_widgets_viewers.c 55 KB

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