uvEditor.ed.gui 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. new GuiControl(UVEditorOverlay, EditorGuiGroup) {
  2. canSaveDynamicFields = "0";
  3. Profile = "ToolsGuiOverlayProfile";
  4. Enabled = "1";
  5. isContainer = "1";
  6. HorizSizing = "right";
  7. VertSizing = "bottom";
  8. Position = "0 0";
  9. Extent = "1024 768";
  10. MinExtent = "8 2";
  11. canSave = "1";
  12. Visible = "1";
  13. hovertime = "1000";
  14. new GuiWindowCtrl(UVEditor){
  15. profile = "ToolsGuiWindowProfile";
  16. HorizSizing = "center";
  17. VertSizing = "center";
  18. resizeWidth = "0";
  19. resizeHeight = "0";
  20. canClose = "1";
  21. canMinimize = "0";
  22. canMaximize = "0";
  23. position = "72 98";
  24. extent =" 453 340";
  25. MinExtent = "453 340";
  26. text = "UV Editor";
  27. closeCommand = "UVEditor.hideDialog();";
  28. EdgeSnap = "0";
  29. canCollapse = "0";
  30. visible = "0";
  31. new GuiTextCtrl() {
  32. text = "0.0";
  33. maxLength = "1024";
  34. Margin = "0 0 0 0";
  35. Padding = "0 0 0 0";
  36. AnchorTop = "1";
  37. AnchorBottom = "0";
  38. AnchorLeft = "1";
  39. AnchorRight = "0";
  40. isContainer = "0";
  41. Profile = "ToolsGuiTextProfile";
  42. HorizSizing = "right";
  43. VertSizing = "bottom";
  44. position = "26 24";
  45. Extent = "32 14";
  46. MinExtent = "8 2";
  47. canSave = "1";
  48. Visible = "1";
  49. tooltipprofile = "ToolsGuiToolTipProfile";
  50. hovertime = "1000";
  51. canSaveDynamicFields = "0";
  52. };
  53. new GuiTextCtrl() {
  54. text = "U";
  55. maxLength = "1024";
  56. Margin = "0 0 0 0";
  57. Padding = "0 0 0 0";
  58. AnchorTop = "1";
  59. AnchorBottom = "0";
  60. AnchorLeft = "1";
  61. AnchorRight = "0";
  62. isContainer = "0";
  63. Profile = "ToolsGuiTextCenterProfile";
  64. HorizSizing = "right";
  65. VertSizing = "bottom";
  66. position = "138 24";
  67. Extent = "32 14";
  68. MinExtent = "8 2";
  69. canSave = "1";
  70. Visible = "1";
  71. tooltipprofile = "ToolsGuiToolTipProfile";
  72. hovertime = "1000";
  73. canSaveDynamicFields = "0";
  74. };
  75. new GuiTextCtrl() {
  76. text = "1.0";
  77. maxLength = "1024";
  78. Margin = "0 0 0 0";
  79. Padding = "0 0 0 0";
  80. AnchorTop = "1";
  81. AnchorBottom = "0";
  82. AnchorLeft = "1";
  83. AnchorRight = "0";
  84. isContainer = "0";
  85. Profile = "ToolsGuiTextRightProfile";
  86. HorizSizing = "right";
  87. VertSizing = "bottom";
  88. position = "250 24";
  89. Extent = "32 14";
  90. MinExtent = "8 2";
  91. canSave = "1";
  92. Visible = "1";
  93. tooltipprofile = "ToolsGuiToolTipProfile";
  94. hovertime = "1000";
  95. canSaveDynamicFields = "0";
  96. };
  97. new GuiTextCtrl() {
  98. text = "0.0";
  99. maxLength = "1024";
  100. Margin = "0 0 0 0";
  101. Padding = "0 0 0 0";
  102. AnchorTop = "1";
  103. AnchorBottom = "0";
  104. AnchorLeft = "1";
  105. AnchorRight = "0";
  106. isContainer = "0";
  107. Profile = "ToolsGuiTextRightProfile";
  108. HorizSizing = "right";
  109. VertSizing = "bottom";
  110. position = "4 36";
  111. Extent = "18 14";
  112. MinExtent = "8 2";
  113. canSave = "1";
  114. Visible = "1";
  115. tooltipprofile = "ToolsGuiToolTipProfile";
  116. hovertime = "1000";
  117. canSaveDynamicFields = "0";
  118. };
  119. new GuiTextCtrl() {
  120. text = "V";
  121. maxLength = "1024";
  122. Margin = "0 0 0 0";
  123. Padding = "0 0 0 0";
  124. AnchorTop = "1";
  125. AnchorBottom = "0";
  126. AnchorLeft = "1";
  127. AnchorRight = "0";
  128. isContainer = "0";
  129. Profile = "ToolsGuiTextRightProfile";
  130. HorizSizing = "right";
  131. VertSizing = "bottom";
  132. position = "4 159";
  133. Extent = "18 14";
  134. MinExtent = "8 2";
  135. canSave = "1";
  136. Visible = "1";
  137. tooltipprofile = "ToolsGuiToolTipProfile";
  138. hovertime = "1000";
  139. canSaveDynamicFields = "0";
  140. };
  141. new GuiTextCtrl() {
  142. text = "1.0";
  143. maxLength = "1024";
  144. Margin = "0 0 0 0";
  145. Padding = "0 0 0 0";
  146. AnchorTop = "1";
  147. AnchorBottom = "0";
  148. AnchorLeft = "1";
  149. AnchorRight = "0";
  150. isContainer = "0";
  151. Profile = "ToolsGuiTextRightProfile";
  152. HorizSizing = "right";
  153. VertSizing = "bottom";
  154. position = "4 282";
  155. Extent = "18 14";
  156. MinExtent = "8 2";
  157. canSave = "1";
  158. Visible = "1";
  159. tooltipprofile = "ToolsGuiToolTipProfile";
  160. hovertime = "1000";
  161. canSaveDynamicFields = "0";
  162. };
  163. new GuiControl(){
  164. HorizSizing = "right";
  165. VertSizing = "bottom";
  166. profile = "ToolsGuiSolidDefaultProfile";
  167. position = "25 37";
  168. extent = "258 258";
  169. };
  170. new GuiBitmapCtrl(){
  171. internalName = "bitmapPreview";
  172. HorizSizing = "right";
  173. VertSizing = "bottom";
  174. profile = "ToolsGuiDefaultProfile";
  175. position = "26 38";
  176. extent = "256 256";
  177. wrap = "0";
  178. bitmap = "";
  179. };
  180. new GuiRectHandles(){
  181. internalName = "uvHandles";
  182. class = "UVEditorRectHandles";
  183. Profile = "ToolsGuiDefaultProfile";
  184. HorizSizing = "right";
  185. VertSizing = "bottom";
  186. position = "26 38";
  187. extent = "256 256";
  188. };
  189. new GuiBitmapBorderCtrl() {
  190. profile = "ToolsGuiGroupBorderProfile";
  191. horizSizing = "width";
  192. vertSizing = "bottom";
  193. position = "26 300";
  194. extent = "256 30";
  195. minExtent = "0 0";
  196. visible = "1";
  197. setFirstResponder = "0";
  198. modal = "1";
  199. helpTag = "0";
  200. new GuiTextCtrl() {
  201. text = "Handle Color:";
  202. maxLength = "1024";
  203. Margin = "0 0 0 0";
  204. Padding = "0 0 0 0";
  205. AnchorTop = "1";
  206. AnchorBottom = "0";
  207. AnchorLeft = "1";
  208. AnchorRight = "0";
  209. isContainer = "0";
  210. Profile = "ToolsGuiTextProfile";
  211. HorizSizing = "right";
  212. VertSizing = "bottom";
  213. position = "10 7";
  214. Extent = "70 14";
  215. MinExtent = "8 2";
  216. canSave = "1";
  217. Visible = "1";
  218. tooltipprofile = "ToolsGuiToolTipProfile";
  219. hovertime = "1000";
  220. canSaveDynamicFields = "0";
  221. };
  222. new GuiPopupMenuCtrlEx(){
  223. internalName = "colorPopup";
  224. Profile = "ToolsGuiPopUpMenuProfile";
  225. Position = "80 5";
  226. Extent = "126 20";
  227. HorizSizing = "right";
  228. VertSizing = "bottom";
  229. Command = "UVEditor.onColorSelect();";
  230. reverseTextList = "0";
  231. };
  232. };
  233. new GuiBitmapBorderCtrl() {
  234. profile = "ToolsGuiGroupBorderProfile";
  235. horizSizing = "width";
  236. vertSizing = "bottom";
  237. position = "292 38";
  238. extent = "151 256";
  239. minExtent = "0 0";
  240. visible = "1";
  241. setFirstResponder = "0";
  242. modal = "1";
  243. helpTag = "0";
  244. new GuiTextCtrl() {
  245. text = "U:";
  246. maxLength = "1024";
  247. Margin = "0 0 0 0";
  248. Padding = "0 0 0 0";
  249. AnchorTop = "1";
  250. AnchorBottom = "0";
  251. AnchorLeft = "1";
  252. AnchorRight = "0";
  253. isContainer = "0";
  254. Profile = "ToolsGuiTextProfile";
  255. HorizSizing = "right";
  256. VertSizing = "bottom";
  257. position = "10 12";
  258. Extent = "32 14";
  259. MinExtent = "8 2";
  260. canSave = "1";
  261. Visible = "1";
  262. tooltipprofile = "ToolsGuiToolTipProfile";
  263. hovertime = "1000";
  264. canSaveDynamicFields = "0";
  265. };
  266. new GuiTextEditCtrl() {
  267. internalName = "UVX";
  268. class = "UVEditorUVTextEdit";
  269. historySize = "0";
  270. password = "0";
  271. tabComplete = "0";
  272. sinkAllKeyEvents = "0";
  273. passwordMask = "*";
  274. maxLength = "1024";
  275. Margin = "0 0 0 0";
  276. Padding = "0 0 0 0";
  277. AnchorTop = "1";
  278. AnchorBottom = "0";
  279. AnchorLeft = "1";
  280. AnchorRight = "0";
  281. isContainer = "0";
  282. Profile = "ToolsGuiNumericTextEditProfile";
  283. HorizSizing = "right";
  284. VertSizing = "bottom";
  285. position = "44 10";
  286. Extent = "64 18";
  287. MinExtent = "8 2";
  288. canSave = "1";
  289. Visible = "1";
  290. tooltipprofile = "ToolsGuiToolTipProfile";
  291. hovertime = "1000";
  292. canSaveDynamicFields = "1";
  293. };
  294. new GuiTextCtrl() {
  295. text = "V:";
  296. maxLength = "1024";
  297. Margin = "0 0 0 0";
  298. Padding = "0 0 0 0";
  299. AnchorTop = "1";
  300. AnchorBottom = "0";
  301. AnchorLeft = "1";
  302. AnchorRight = "0";
  303. isContainer = "0";
  304. Profile = "ToolsGuiTextProfile";
  305. HorizSizing = "right";
  306. VertSizing = "bottom";
  307. position = "10 32";
  308. Extent = "32 14";
  309. MinExtent = "8 2";
  310. canSave = "1";
  311. Visible = "1";
  312. tooltipprofile = "ToolsGuiToolTipProfile";
  313. hovertime = "1000";
  314. canSaveDynamicFields = "0";
  315. };
  316. new GuiTextEditCtrl() {
  317. internalName = "UVY";
  318. class = "UVEditorUVTextEdit";
  319. historySize = "0";
  320. password = "0";
  321. tabComplete = "0";
  322. sinkAllKeyEvents = "0";
  323. passwordMask = "*";
  324. maxLength = "1024";
  325. Margin = "0 0 0 0";
  326. Padding = "0 0 0 0";
  327. AnchorTop = "1";
  328. AnchorBottom = "0";
  329. AnchorLeft = "1";
  330. AnchorRight = "0";
  331. isContainer = "0";
  332. Profile = "ToolsGuiNumericTextEditProfile";
  333. HorizSizing = "right";
  334. VertSizing = "bottom";
  335. position = "44 30";
  336. Extent = "64 18";
  337. MinExtent = "8 2";
  338. canSave = "1";
  339. Visible = "1";
  340. tooltipprofile = "ToolsGuiToolTipProfile";
  341. hovertime = "1000";
  342. canSaveDynamicFields = "1";
  343. };
  344. new GuiTextCtrl() {
  345. text = "Width:";
  346. maxLength = "1024";
  347. Margin = "0 0 0 0";
  348. Padding = "0 0 0 0";
  349. AnchorTop = "1";
  350. AnchorBottom = "0";
  351. AnchorLeft = "1";
  352. AnchorRight = "0";
  353. isContainer = "0";
  354. Profile = "ToolsGuiTextProfile";
  355. HorizSizing = "right";
  356. VertSizing = "bottom";
  357. position = "10 52";
  358. Extent = "32 14";
  359. MinExtent = "8 2";
  360. canSave = "1";
  361. Visible = "1";
  362. tooltipprofile = "ToolsGuiToolTipProfile";
  363. hovertime = "1000";
  364. canSaveDynamicFields = "0";
  365. };
  366. new GuiTextEditCtrl() {
  367. internalName = "UVW";
  368. class = "UVEditorUVTextEdit";
  369. historySize = "0";
  370. password = "0";
  371. tabComplete = "0";
  372. sinkAllKeyEvents = "0";
  373. passwordMask = "*";
  374. maxLength = "1024";
  375. Margin = "0 0 0 0";
  376. Padding = "0 0 0 0";
  377. AnchorTop = "1";
  378. AnchorBottom = "0";
  379. AnchorLeft = "1";
  380. AnchorRight = "0";
  381. isContainer = "0";
  382. Profile = "ToolsGuiNumericTextEditProfile";
  383. HorizSizing = "right";
  384. VertSizing = "bottom";
  385. position = "44 50";
  386. Extent = "64 18";
  387. MinExtent = "8 2";
  388. canSave = "1";
  389. Visible = "1";
  390. tooltipprofile = "ToolsGuiToolTipProfile";
  391. hovertime = "1000";
  392. canSaveDynamicFields = "1";
  393. };
  394. new GuiTextCtrl() {
  395. text = "Height:";
  396. maxLength = "1024";
  397. Margin = "0 0 0 0";
  398. Padding = "0 0 0 0";
  399. AnchorTop = "1";
  400. AnchorBottom = "0";
  401. AnchorLeft = "1";
  402. AnchorRight = "0";
  403. isContainer = "0";
  404. Profile = "ToolsGuiTextProfile";
  405. HorizSizing = "right";
  406. VertSizing = "bottom";
  407. position = "10 72";
  408. Extent = "32 14";
  409. MinExtent = "8 2";
  410. canSave = "1";
  411. Visible = "1";
  412. tooltipprofile = "ToolsGuiToolTipProfile";
  413. hovertime = "1000";
  414. canSaveDynamicFields = "0";
  415. };
  416. new GuiTextEditCtrl() {
  417. internalName = "UVH";
  418. class = "UVEditorUVTextEdit";
  419. historySize = "0";
  420. password = "0";
  421. tabComplete = "0";
  422. sinkAllKeyEvents = "0";
  423. passwordMask = "*";
  424. maxLength = "1024";
  425. Margin = "0 0 0 0";
  426. Padding = "0 0 0 0";
  427. AnchorTop = "1";
  428. AnchorBottom = "0";
  429. AnchorLeft = "1";
  430. AnchorRight = "0";
  431. isContainer = "0";
  432. Profile = "ToolsGuiNumericTextEditProfile";
  433. HorizSizing = "right";
  434. VertSizing = "bottom";
  435. position = "44 70";
  436. Extent = "64 18";
  437. MinExtent = "8 2";
  438. canSave = "1";
  439. Visible = "1";
  440. tooltipprofile = "ToolsGuiToolTipProfile";
  441. hovertime = "1000";
  442. canSaveDynamicFields = "1";
  443. };
  444. new GuiButtonCtrl(){
  445. HorizSizing = "right";
  446. VertSizing = "top";
  447. profile = "ToolsGuiButtonProfile";
  448. position = "44 94";
  449. extent = "64 20";
  450. text = "Reset";
  451. command = "UVEditor.reset();";
  452. tooltip = "Reset the UV fields to their original values.";
  453. };
  454. };
  455. new GuiButtonCtrl(){
  456. internalName = "OKButton";
  457. HorizSizing = "left";
  458. VertSizing = "top";
  459. profile = "ToolsGuiButtonProfile";
  460. position = "292 306";
  461. extent = "94 24";
  462. text = "OK";
  463. command = "UVEditor.apply();";
  464. Accelerator = "return";
  465. };
  466. new GuiButtonCtrl(){
  467. HorizSizing = "left";
  468. VertSizing = "top";
  469. profile = "ToolsGuiButtonProfile";
  470. position = "391 306";
  471. extent = "52 24";
  472. text = "Cancel";
  473. command = "UVEditor.hideDialog();";
  474. Accelerator = "escape";
  475. };
  476. };
  477. };
  478. //-----------------------------------------------------------------------------
  479. function UVEditor::showDialog( %this, %applyCallback, %obj, %uv)
  480. {
  481. // Set the select callback
  482. UVEditor.applyCallback = %applyCallback;
  483. // Set the initial UV coordinates
  484. UVEditor.originalUV = %uv;
  485. UVEditor-->uvHandles.handleRect = %uv;
  486. UVEditor.setTextValues(%uv);
  487. // Get the preview bitmap. Code copied from Material Selector.
  488. %material = %obj.material;
  489. if( %material.toneMap[0] $= "" && %material.diffuseMap[0] $= "" && !isObject(%material.cubemap) )
  490. {
  491. %previewImage = "core/art/warnmat";
  492. }
  493. else
  494. {
  495. if( %material.toneMap[0] !$= "" )
  496. %previewImage = %material.toneMap[0];
  497. else if( %material.diffuseMap[0] !$= "" )
  498. %previewImage = %material.diffuseMap[0];
  499. else if( %material.cubemap.cubeFace[0] !$= "" )
  500. %previewImage = %material.cubemap.cubeFace[0];
  501. %materialDiffuse = %previewImage;
  502. %materialPath = %material.getFilename();
  503. if( strchr( %materialDiffuse, "/") $= "" )
  504. {
  505. %k = 0;
  506. while( strpos( %materialPath, "/", %k ) != -1 )
  507. {
  508. %foo = strpos( %materialPath, "/", %k );
  509. %k = %foo + 1;
  510. }
  511. %foobar = getSubStr( %materialPath , %k , 99 );
  512. %previewImage = strreplace( %materialPath, %foobar, %previewImage );
  513. }
  514. else
  515. %previewImage = strreplace( %materialPath, %materialPath, %previewImage );
  516. }
  517. UVEditor-->bitmapPreview.setBitmap(%previewImage);
  518. // Set up the color popup
  519. %popup = UVEditor-->colorPopup;
  520. %popup.clear();
  521. %popup.add("Default1|255|134|0");
  522. %popup.add("Default2|0|121|255");
  523. %popup.add("Black|0|0|0");
  524. %popup.add("Gray|100|100|100");
  525. %popup.add("White|255|255|255");
  526. %popup.add("Red|255|0|0");
  527. %popup.add("Green|0|255|0");
  528. %popup.add("Blue|0|0|255");
  529. %popup.add("Yellow|255|255|0");
  530. %popup.add("Magenta|255|0|255");
  531. %popup.add("Cyan|0|255|255");
  532. %popup.setSelected(EditorSettings.value("WorldEditor/Color/uvEditorHandleColor"));
  533. UVEditor-->uvHandles.useCustomColor = true;
  534. UVEditor-->uvHandles.handleColor = %popup.getColorById(%popup.getSelected());
  535. Canvas.pushDialog(UVEditorOverlay);
  536. UVEditor.setVisible(1);
  537. }
  538. function UVEditor::hideDialog( %this )
  539. {
  540. UVEditor.setVisible(0);
  541. Canvas.popDialog(UVEditorOverlay);
  542. }
  543. function UVEditor::apply( %this )
  544. {
  545. eval( "" @ UVEditor.applyCallback @ "(\"" @ UVEditor-->uvHandles.handleRect @ "\");");
  546. UVEditor.hideDialog();
  547. }
  548. function UVEditor::reset( %this )
  549. {
  550. UVEditor-->uvHandles.handleRect = UVEditor.originalUV;
  551. UVEditor.setTextValues(UVEditor.originalUV);
  552. }
  553. function UVEditor::setTextValues( %this, %uv )
  554. {
  555. UVEditor-->UVX.setText( getWord(%uv, 0) );
  556. UVEditor-->UVY.setText( getWord(%uv, 1) );
  557. UVEditor-->UVW.setText( getWord(%uv, 2) );
  558. UVEditor-->UVH.setText( getWord(%uv, 3) );
  559. }
  560. function UVEditor::onColorSelect( %this )
  561. {
  562. UVEditor-->uvHandles.useCustomColor = true;
  563. %sel = $ThisControl.getSelected();
  564. UVEditor-->uvHandles.handleColor = $ThisControl.getColorById(%sel);
  565. EditorSettings.setValue( "WorldEditor/Color/uvEditorHandleColor", %sel );
  566. }
  567. //-----------------------------------------------------------------------------
  568. function UVEditorRectHandles::onHandleRectChange( %this )
  569. {
  570. %uv = UVEditor-->uvHandles.handleRect;
  571. UVEditor.setTextValues(%uv);
  572. }
  573. //-----------------------------------------------------------------------------
  574. function UVEditorUVTextEdit::onValidate( %this )
  575. {
  576. %u = UVEditor-->UVX.getValue();
  577. %v = UVEditor-->UVY.getValue();
  578. %w = UVEditor-->UVW.getValue();
  579. %h = UVEditor-->UVH.getValue();
  580. // Check limits
  581. if(%u < 0)
  582. %u = 0;
  583. if(%u > 1)
  584. %u = 1;
  585. if(%v < 0)
  586. %v = 0;
  587. if(%v > 1)
  588. %v = 1;
  589. if(%w < 0)
  590. %w = 0;
  591. if(%w > 1)
  592. %w = 1;
  593. if(%h < 0)
  594. %h = 0;
  595. if(%h > 1)
  596. %h = 1;
  597. if((%u+%w) > 1)
  598. %w = 1 - %u;
  599. if((%v+%h) > 1)
  600. %h = 1 - %v;
  601. // Apply values
  602. UVEditor-->UVX.setText( %u );
  603. UVEditor-->UVY.setText( %v );
  604. UVEditor-->UVW.setText( %w );
  605. UVEditor-->UVH.setText( %h );
  606. UVEditor-->uvHandles.handleRect = %u SPC %v SPC %w SPC %h;
  607. }
  608. function UVEditorUVTextEdit::onGainFirstResponder( %this )
  609. {
  610. %this.selectAllText();
  611. }