*/}}

la_widgets_viewers.c 53 KB

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