*/}}

la_widgets_viewers.c 57 KB

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