*/}}

la_widgets_viewers.c 61 KB

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