UIHeader.hx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. package arm.ui;
  2. import kha.System;
  3. import zui.Zui;
  4. import zui.Id;
  5. import iron.RenderPath;
  6. import arm.node.MakeMaterial;
  7. import arm.util.UVUtil;
  8. import arm.util.RenderUtil;
  9. import arm.io.ImportFont;
  10. import arm.Enums;
  11. class UIHeader {
  12. public static var inst: UIHeader;
  13. public static inline var defaultHeaderH = 28;
  14. public var headerHandle = new Handle({layout: Horizontal});
  15. public var headerh = defaultHeaderH;
  16. public var worktab = Id.handle();
  17. public function new() {
  18. inst = this;
  19. }
  20. @:access(zui.Zui)
  21. public function renderUI(g: kha.graphics2.Graphics) {
  22. var ui = UISidebar.inst.ui;
  23. var panelx = iron.App.x();
  24. if (ui.window(headerHandle, panelx, headerh, System.windowWidth() - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW], Std.int(defaultHeaderH * ui.SCALE()))) {
  25. ui._y += 2;
  26. if (Context.tool == ToolColorId) {
  27. ui.text(tr("Picked Color"));
  28. if (Context.colorIdPicked) {
  29. ui.image(RenderPath.active.renderTargets.get("texpaint_colorid").image, 0xffffffff, 64);
  30. }
  31. if (ui.button(tr("Clear"))) Context.colorIdPicked = false;
  32. ui.text(tr("Color ID Map"));
  33. var cid = ui.combo(Context.colorIdHandle, App.enumTexts("TEX_IMAGE"), tr("Color ID"));
  34. if (Context.colorIdHandle.changed) Context.ddirty = 2;
  35. if (Project.assets.length > 0) ui.image(Project.getImage(Project.assets[cid]));
  36. }
  37. else if (Context.tool == ToolPicker) {
  38. var baseRPicked = Math.round(Context.swatch.base.R * 10) / 10;
  39. var baseGPicked = Math.round(Context.swatch.base.G * 10) / 10;
  40. var baseBPicked = Math.round(Context.swatch.base.B * 10) / 10;
  41. var normalRPicked = Math.round(Context.swatch.normal.R * 10) / 10;
  42. var normalGPicked = Math.round(Context.swatch.normal.G * 10) / 10;
  43. var normalBPicked = Math.round(Context.swatch.normal.B * 10) / 10;
  44. var occlusionPicked = Math.round(Context.swatch.occlusion * 100) / 100;
  45. var roughnessPicked = Math.round(Context.swatch.roughness * 100) / 100;
  46. var metallicPicked = Math.round(Context.swatch.metallic * 100) / 100;
  47. var h = Id.handle();
  48. h.color.R = baseRPicked;
  49. h.color.G = baseGPicked;
  50. h.color.B = baseBPicked;
  51. ui.text("", 0, h.color);
  52. if (ui.isHovered && ui.inputReleased) {
  53. UIMenu.draw(function(ui) {
  54. ui.fill(0, 0, ui._w / ui.ops.scaleFactor, ui.t.ELEMENT_H * 9, ui.t.SEPARATOR_COL);
  55. ui.changed = false;
  56. zui.Ext.colorWheel(ui, h, false, null, false);
  57. if (ui.changed) UIMenu.keepOpen = true;
  58. }, 10);
  59. }
  60. ui.text(tr("Base") + ' ($baseRPicked,$baseGPicked,$baseBPicked)');
  61. ui.text(tr("Normal") + ' ($normalRPicked,$normalGPicked,$normalBPicked)');
  62. ui.text(tr("Occlusion") + ' ($occlusionPicked)');
  63. ui.text(tr("Roughness") + ' ($roughnessPicked)');
  64. ui.text(tr("Metallic") + ' ($metallicPicked)');
  65. Context.pickerSelectMaterial = ui.check(Id.handle({selected: Context.pickerSelectMaterial}), tr("Select Material"));
  66. ui.combo(Context.pickerMaskHandle, [tr("None"), tr("Material")], tr("Mask"), true);
  67. if (Context.pickerMaskHandle.changed) {
  68. MakeMaterial.parsePaintMaterial();
  69. }
  70. }
  71. else if (Context.tool == ToolBake) {
  72. ui.changed = false;
  73. #if (kha_direct3d12 || kha_vulkan)
  74. var baking = Context.pdirty > 0;
  75. var rtBake = Context.bakeType == BakeAO || Context.bakeType == BakeLightmap || Context.bakeType == BakeBentNormal || Context.bakeType == BakeThickness;
  76. if (baking && ui.button(tr("Stop"))) {
  77. Context.pdirty = 0;
  78. Context.rdirty = 2;
  79. }
  80. #else
  81. var baking = false;
  82. var rtBake = false;
  83. #end
  84. if (!baking && ui.button(tr("Bake"))) {
  85. Context.pdirty = rtBake ? Context.bakeSamples : 1;
  86. Context.rdirty = 3;
  87. App.notifyOnNextFrame(function() {
  88. Context.layerPreviewDirty = true;
  89. });
  90. UISidebar.inst.hwnd0.redraws = 2;
  91. History.pushUndo = true;
  92. }
  93. var bakeHandle = Id.handle({position: Context.bakeType});
  94. var bakes = [
  95. tr("AO"),
  96. tr("Curvature"),
  97. tr("Normal"),
  98. tr("Object Normal"),
  99. tr("Height"),
  100. tr("Derivative"),
  101. tr("Position"),
  102. tr("TexCoord"),
  103. tr("Material ID"),
  104. tr("Object ID"),
  105. tr("Vertex Color"),
  106. ];
  107. #if (kha_direct3d12 || kha_vulkan)
  108. bakes.push(tr("Lightmap"));
  109. bakes.push(tr("Bent Normal"));
  110. bakes.push(tr("Thickness"));
  111. #end
  112. Context.bakeType = ui.combo(bakeHandle, bakes, tr("Bake"));
  113. #if (kha_direct3d12 || kha_vulkan)
  114. if (rtBake) {
  115. var samplesHandle = Id.handle({value: Context.bakeSamples});
  116. Context.bakeSamples = Std.int(ui.slider(samplesHandle, tr("Samples"), 1, 512, true, 1));
  117. }
  118. #end
  119. if (Context.bakeType == BakeNormalObject || Context.bakeType == BakePosition || Context.bakeType == BakeBentNormal) {
  120. var bakeUpAxisHandle = Id.handle({position: Context.bakeUpAxis});
  121. Context.bakeUpAxis = ui.combo(bakeUpAxisHandle, [tr("Z"), tr("Y")], tr("Up Axis"), true);
  122. }
  123. if (Context.bakeType == BakeAO || Context.bakeType == BakeCurvature) {
  124. var bakeAxisHandle = Id.handle({position: Context.bakeAxis});
  125. Context.bakeAxis = ui.combo(bakeAxisHandle, [tr("XYZ"), tr("X"), tr("Y"), tr("Z"), tr("-X"), tr("-Y"), tr("-Z")], tr("Axis"), true);
  126. }
  127. if (Context.bakeType == BakeAO) {
  128. var strengthHandle = Id.handle({value: Context.bakeAoStrength});
  129. Context.bakeAoStrength = ui.slider(strengthHandle, tr("Strength"), 0.0, 2.0, true);
  130. var radiusHandle = Id.handle({value: Context.bakeAoRadius});
  131. Context.bakeAoRadius = ui.slider(radiusHandle, tr("Radius"), 0.0, 2.0, true);
  132. var offsetHandle = Id.handle({value: Context.bakeAoOffset});
  133. Context.bakeAoOffset = ui.slider(offsetHandle, tr("Offset"), 0.0, 2.0, true);
  134. }
  135. #if (kha_direct3d12 || kha_vulkan)
  136. if (rtBake) {
  137. ui.text(tr("Rays/pix:") + ' ${arm.render.RenderPathRaytraceBake.raysPix}');
  138. ui.text(tr("Rays/sec:") + ' ${arm.render.RenderPathRaytraceBake.raysSec}');
  139. }
  140. #end
  141. if (Context.bakeType == BakeCurvature) {
  142. var strengthHandle = Id.handle({value: Context.bakeCurvStrength});
  143. Context.bakeCurvStrength = ui.slider(strengthHandle, tr("Strength"), 0.0, 2.0, true);
  144. var radiusHandle = Id.handle({value: Context.bakeCurvRadius});
  145. Context.bakeCurvRadius = ui.slider(radiusHandle, tr("Radius"), 0.0, 2.0, true);
  146. var offsetHandle = Id.handle({value: Context.bakeCurvOffset});
  147. Context.bakeCurvOffset = ui.slider(offsetHandle, tr("Offset"), -2.0, 2.0, true);
  148. var smoothHandle = Id.handle({value: Context.bakeCurvSmooth});
  149. Context.bakeCurvSmooth = Std.int(ui.slider(smoothHandle, tr("Smooth"), 0, 5, false, 1));
  150. }
  151. if (Context.bakeType == BakeNormal || Context.bakeType == BakeHeight || Context.bakeType == BakeDerivative) {
  152. var ar = [for (p in Project.paintObjects) p.name];
  153. var polyHandle = Id.handle({position: Context.bakeHighPoly});
  154. Context.bakeHighPoly = ui.combo(polyHandle, ar, tr("High Poly"));
  155. }
  156. if (ui.changed) {
  157. MakeMaterial.parsePaintMaterial();
  158. }
  159. }
  160. else if (Context.tool == ToolBrush ||
  161. Context.tool == ToolEraser ||
  162. Context.tool == ToolFill ||
  163. Context.tool == ToolDecal ||
  164. Context.tool == ToolText ||
  165. Context.tool == ToolClone ||
  166. Context.tool == ToolBlur ||
  167. Context.tool == ToolParticle) {
  168. var decal = Context.tool == ToolDecal || Context.tool == ToolText;
  169. var decalMask = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutDown);
  170. if (Context.tool != ToolFill) {
  171. if (decalMask) {
  172. Context.brushDecalMaskRadius = ui.slider(Context.brushDecalMaskRadiusHandle, tr("Radius"), 0.01, 2.0, true);
  173. }
  174. else {
  175. Context.brushRadius = ui.slider(Context.brushRadiusHandle, tr("Radius"), 0.01, 2.0, true);
  176. }
  177. }
  178. if (Context.tool == ToolDecal || Context.tool == ToolText) {
  179. Context.brushScaleX = ui.slider(Context.brushScaleXHandle, tr("Scale X"), 0.01, 2.0, true);
  180. }
  181. if (Context.tool == ToolBrush ||
  182. Context.tool == ToolFill ||
  183. Context.tool == ToolDecal ||
  184. Context.tool == ToolText) {
  185. var brushScaleHandle = Id.handle({value: Context.brushScale});
  186. Context.brushScale = ui.slider(brushScaleHandle, tr("UV Scale"), 0.01, 5.0, true);
  187. if (brushScaleHandle.changed) {
  188. if (Context.tool == ToolDecal || Context.tool == ToolText) {
  189. ui.g.end();
  190. RenderUtil.makeDecalPreview();
  191. ui.g.begin(false);
  192. }
  193. }
  194. Context.brushAngle = ui.slider(Context.brushAngleHandle, tr("Angle"), 0.0, 360.0, true, 1);
  195. if (Context.brushAngleHandle.changed) {
  196. MakeMaterial.parsePaintMaterial();
  197. }
  198. }
  199. Context.brushOpacity = ui.slider(Context.brushOpacityHandle, tr("Opacity"), 0.0, 1.0, true);
  200. if (Context.tool == ToolBrush || Context.tool == ToolEraser || decalMask) {
  201. Context.brushHardness = ui.slider(Id.handle({value: Context.brushHardness}), tr("Hardness"), 0.0, 1.0, true);
  202. }
  203. if (Context.tool != ToolEraser) {
  204. var brushBlendingHandle = Id.handle({value: Context.brushBlending});
  205. Context.brushBlending = ui.combo(brushBlendingHandle, [
  206. tr("Mix"),
  207. tr("Darken"),
  208. tr("Multiply"),
  209. tr("Burn"),
  210. tr("Lighten"),
  211. tr("Screen"),
  212. tr("Dodge"),
  213. tr("Add"),
  214. tr("Overlay"),
  215. tr("Soft Light"),
  216. tr("Linear Light"),
  217. tr("Difference"),
  218. tr("Subtract"),
  219. tr("Divide"),
  220. tr("Hue"),
  221. tr("Saturation"),
  222. tr("Color"),
  223. tr("Value"),
  224. ], tr("Blending"));
  225. if (brushBlendingHandle.changed) {
  226. MakeMaterial.parsePaintMaterial();
  227. }
  228. }
  229. if (Context.tool == ToolBrush || Context.tool == ToolFill) {
  230. var paintHandle = Id.handle();
  231. Context.brushPaint = ui.combo(paintHandle, [tr("UV Map"), tr("Triplanar"), tr("Project")], tr("TexCoord"));
  232. if (paintHandle.changed) {
  233. MakeMaterial.parsePaintMaterial();
  234. }
  235. }
  236. if (Context.tool == ToolText) {
  237. var h = Id.handle();
  238. h.text = Context.textToolText;
  239. Context.textToolText = ui.textInput(h, "");
  240. if (h.changed) {
  241. ui.g.end();
  242. RenderUtil.makeTextPreview();
  243. RenderUtil.makeDecalPreview();
  244. ui.g.begin(false);
  245. }
  246. }
  247. if (Context.tool == ToolFill) {
  248. ui.combo(Context.fillTypeHandle, [tr("Object"), tr("Face"), tr("Angle"), tr("UV Island")], tr("Fill Mode"));
  249. if (Context.fillTypeHandle.changed) {
  250. if (Context.fillTypeHandle.position == FillFace) {
  251. ui.g.end();
  252. // UVUtil.cacheUVMap();
  253. UVUtil.cacheTriangleMap();
  254. ui.g.begin(false);
  255. // wireframeHandle.selected = drawWireframe = true;
  256. }
  257. MakeMaterial.parsePaintMaterial();
  258. MakeMaterial.parseMeshMaterial();
  259. }
  260. }
  261. else {
  262. var _w = ui._w;
  263. var sc = ui.SCALE();
  264. ui._w = Std.int(60 * sc);
  265. var xrayHandle = Id.handle({selected: Context.xray});
  266. Context.xray = ui.check(xrayHandle, tr("X-Ray"));
  267. if (xrayHandle.changed) {
  268. MakeMaterial.parsePaintMaterial();
  269. }
  270. var symXHandle = Id.handle({selected: false});
  271. var symYHandle = Id.handle({selected: false});
  272. var symZHandle = Id.handle({selected: false});
  273. #if krom_ios
  274. ui._x -= 10 * sc;
  275. #else
  276. ui._w = Std.int(56 * sc);
  277. ui.text(tr("Symmetry"));
  278. #end
  279. ui._w = Std.int(25 * sc);
  280. Context.symX = ui.check(symXHandle, tr("X"));
  281. Context.symY = ui.check(symYHandle, tr("Y"));
  282. Context.symZ = ui.check(symZHandle, tr("Z"));
  283. if (symXHandle.changed || symYHandle.changed || symZHandle.changed) {
  284. MakeMaterial.parsePaintMaterial();
  285. }
  286. ui._w = _w;
  287. }
  288. if (Context.tool == ToolBlur) {
  289. ui._x += 10 * ui.SCALE();
  290. var dirHandle = Id.handle({selected: false});
  291. Context.blurDirectional = ui.check(dirHandle, tr("Directional"));
  292. if (dirHandle.changed) {
  293. MakeMaterial.parsePaintMaterial();
  294. }
  295. }
  296. }
  297. }
  298. }
  299. }