diff --git a/Sources/arm/App.hx b/Sources/arm/App.hx index b540111e..4fdd6556 100644 --- a/Sources/arm/App.hx +++ b/Sources/arm/App.hx @@ -83,10 +83,8 @@ class App extends iron.Trait { dropPath = StringTools.rtrim(dropPath); }); - #if kha_krom - if (kha.System.systemId == "Windows") { - untyped Krom.setSaveAndQuitCallback(saveAndQuitCallback); - } + #if krom_windows + untyped Krom.setSaveAndQuitCallback(saveAndQuitCallback); #end iron.data.Data.getFont("font_default.ttf", function(f:kha.Font) { @@ -352,7 +350,11 @@ class App extends iron.Trait { } if (dropPath != "") { - var wait = kha.System.systemId == "Linux" && !mouse.moved; // Mouse coords not updated on Linux during drag + #if krom_linux + var wait = !mouse.moved; // Mouse coords not updated on Linux during drag + #else + var wait = false; + #end if (!wait) { dropX = mouse.x + App.x(); dropY = mouse.y + App.y(); @@ -365,8 +367,8 @@ class App extends iron.Trait { var decal = UITrait.inst.selectedTool == ToolDecal || UITrait.inst.selectedTool == ToolText; var isPicker = UITrait.inst.selectedTool == ToolPicker; - Zui.alwaysRedrawWindow = - kha.System.systemId != "Windows" || + #if krom_windows + Zui.alwaysRedrawWindow = showMenu || showBox || isDragging || @@ -375,6 +377,7 @@ class App extends iron.Trait { UIView2D.inst.show || !UITrait.inst.brush3d || UITrait.inst.frame < 3; + #end if (Zui.alwaysRedrawWindow && UITrait.inst.ddirty < 0) UITrait.inst.ddirty = 0; } diff --git a/Sources/arm/Importer.hx b/Sources/arm/Importer.hx index 35fec675..7aa17732 100644 --- a/Sources/arm/Importer.hx +++ b/Sources/arm/Importer.hx @@ -57,10 +57,18 @@ class Importer { static function importFolder(path:String) { #if kha_krom - var systemId = kha.System.systemId; - var cmd = systemId == "Windows" ? "dir /b " : "ls "; - var sep = systemId == "Windows" ? "\\" : "/"; - var save = systemId == "Linux" ? "/tmp" : Krom.savePath(); + #if krom_windows + var cmd = "dir /b "; + var sep = "\\"; + #else + var cmd = "ls "; + var sep = "/"; + #end + #if krom_linux + var save = "/tmp"; + #else + var save = Krom.savePath(); + #end save += sep + "dir.txt"; Krom.sysCommand(cmd + '"' + path + '"' + ' > ' + '"' + save + '"'); var str = haxe.io.Bytes.ofData(Krom.loadBlob(save)).toString(); @@ -79,7 +87,9 @@ class Importer { if (!Format.checkTextureFormat(f)) continue; f = path + sep + f; - if (systemId == "Windows") f = StringTools.replace(f, "/", "\\"); + #if krom_windows + f = StringTools.replace(f, "/", "\\"); + #end // TODO: handle -albedo @@ -249,10 +259,15 @@ class Importer { (image.width == 1024 || image.width == 2048 || image.width == 4096)) { #if kha_krom - var sys = kha.System.systemId; var dataPath = iron.data.Data.dataPath; var p = Krom.getFilesLocation() + '/' + dataPath; - var cmft = p + "/cmft" + (sys == "Windows" ? ".exe" : sys == "Linux" ? "-linux64" : "-osx"); + #if krom_windows + var cmft = p + "/cmft.exe"; + #elseif krom_linux + var cmft = p + "/cmft-linux64"; + #else + var cmft = p + "/cmft-osx"; + #end var cmd = ''; var tmp = Krom.getFilesLocation() + '/' + dataPath; @@ -454,13 +469,12 @@ class Importer { // Convert image path from relative to absolute var isAbsolute = file.charAt(0) == "/" || file.charAt(1) == ":"; var abs = isAbsolute ? file : base + file; + #if krom_windows + var exists = Krom.sysCommand('IF EXIST "' + abs + '" EXIT /b 1'); + #else var exists = 1; - if (kha.System.systemId == "Windows") { - #if kha_krom - exists = Krom.sysCommand('IF EXIST "' + abs + '" EXIT /b 1'); - #end - } - //else { test -e file && echo 1 || echo 0 } + // { test -e file && echo 1 || echo 0 } + #end if (exists == 0) { trace("Could not locate texture " + abs); var b = haxe.io.Bytes.alloc(4); diff --git a/Sources/arm/Project.hx b/Sources/arm/Project.hx index ca05453e..c315f211 100644 --- a/Sources/arm/Project.hx +++ b/Sources/arm/Project.hx @@ -163,6 +163,7 @@ class Project { if (UITrait.inst.projectType == 1) { var mesh = new iron.format.proc.Plane(1, 1, 512, 512); + // var mesh = new iron.format.proc.Sphere(1, 512, 256); var raw = { name: "PlaneTess", vertex_arrays: [ @@ -179,7 +180,7 @@ class Project { var md = new MeshData(raw, function(md:MeshData) {}); iron.data.Data.cachedMeshes.set("ScenePlaneTess", md); - ViewportUtil.setView(0, 0, 1, 0, 0, 0); // Top + // ViewportUtil.setView(0, 0, 1, 0, 0, 0); // Top } var n = UITrait.inst.projectType == 0 ? "Cube" : "PlaneTess"; @@ -274,13 +275,12 @@ class Project { // Convert image path from relative to absolute var isAbsolute = file.charAt(0) == "/" || file.charAt(1) == ":"; var abs = isAbsolute ? file : base + file; + #if krom_windows + var exists = Krom.sysCommand('IF EXIST "' + abs + '" EXIT /b 1'); + #else var exists = 1; - if (kha.System.systemId == "Windows") { - #if kha_krom - exists = Krom.sysCommand('IF EXIST "' + abs + '" EXIT /b 1'); - #end - } - //else { test -e file && echo 1 || echo 0 } + // { test -e file && echo 1 || echo 0 } + #end if (exists == 0) { trace("Could not locate texture " + abs); var b = haxe.io.Bytes.alloc(4); diff --git a/Sources/arm/ui/UIFiles.hx b/Sources/arm/ui/UIFiles.hx index c46aabe9..0df12529 100644 --- a/Sources/arm/ui/UIFiles.hx +++ b/Sources/arm/ui/UIFiles.hx @@ -21,7 +21,11 @@ class UIFiles { if (!App.checkAscii(App.path)) return; App.path = StringTools.replace(App.path, "\\\\", "\\"); App.path = StringTools.replace(App.path, "\r", ""); - var sep = kha.System.systemId == "Windows" ? "\\" : "/"; + #if krom_windows + var sep = "\\"; + #else + var sep = "/"; + #end App.filenameHandle.text = App.path.substr(App.path.lastIndexOf(sep) + 1); if (App.foldersOnly) App.path = App.path.substr(0, App.path.lastIndexOf(sep)); App.filesDone(App.path); @@ -61,7 +65,11 @@ class UIFiles { if (Format.checkTextureFormat(App.path) || Format.checkMeshFormat(App.path) || Format.checkProjectFormat(App.path)) { App.showFiles = false; App.filesDone(App.path); - var sep = kha.System.systemId == "Windows" ? "\\" : "/"; + #if krom_windows + var sep = "\\"; + #else + var sep = "/"; + #end pathHandle.text = pathHandle.text.substr(0, pathHandle.text.lastIndexOf(sep)); App.whandle.redraws = 2; UITrait.inst.ddirty = 2; diff --git a/Sources/arm/ui/UIMenu.hx b/Sources/arm/ui/UIMenu.hx index 2a28f3c5..350c9913 100644 --- a/Sources/arm/ui/UIMenu.hx +++ b/Sources/arm/ui/UIMenu.hx @@ -99,30 +99,22 @@ class UIMenu { } else if (menuCategory == 3) { if (ui.button("Manual", Left)) { - #if kha_krom - if (kha.System.systemId == "Windows") { - Krom.sysCommand('explorer "https://armorpaint.org/manual"'); - } - else if (kha.System.systemId == "Linux") { - Krom.sysCommand('xdg-open "https://armorpaint.org/manual"'); - } - else { - Krom.sysCommand('open "https://armorpaint.org/manual"'); - } + #if krom_windows + Krom.sysCommand('explorer "https://armorpaint.org/manual"'); + #elseif krom_linux + Krom.sysCommand('xdg-open "https://armorpaint.org/manual"'); + #else + Krom.sysCommand('open "https://armorpaint.org/manual"'); #end } if (ui.button("Report Bug", Left)) { // var url = "https://github.com/armory3d/armorpaint/issues/new?body=body"; - #if kha_krom - if (kha.System.systemId == "Windows") { - Krom.sysCommand('explorer "https://github.com/armory3d/armorpaint/issues"'); - } - else if (kha.System.systemId == "Linux") { - Krom.sysCommand('xdg-open "https://github.com/armory3d/armorpaint/issues"'); - } - else { - Krom.sysCommand('open "https://github.com/armory3d/armorpaint/issues"'); - } + #if krom_windows + Krom.sysCommand('explorer "https://github.com/armory3d/armorpaint/issues"'); + #elseif krom_linux + Krom.sysCommand('xdg-open "https://github.com/armory3d/armorpaint/issues"'); + #else + Krom.sysCommand('open "https://github.com/armory3d/armorpaint/issues"'); #end } // if (ui.button("Request Feature", Left)) {} @@ -131,12 +123,11 @@ class UIMenu { #if kha_krom var outFile = Krom.getFilesLocation() + '/' + iron.data.Data.dataPath + "update.txt"; var uri = "'https://luboslenco.gitlab.io/armorpaint/index.html'"; - if (kha.System.systemId == "Windows") { - Krom.sysCommand('powershell -c "Invoke-WebRequest -Uri ' + uri + " -OutFile '" + outFile + "'"); - } - else { - Krom.sysCommand('curl ' + uri + ' -o ' + outFile); - } + #if krom_windows + Krom.sysCommand('powershell -c "Invoke-WebRequest -Uri ' + uri + " -OutFile '" + outFile + "'"); + #else + Krom.sysCommand('curl ' + uri + ' -o ' + outFile); + #end // Compare versions iron.data.Data.getBlob(outFile, function(blob:kha.Blob) { var update = haxe.Json.parse(blob.toString()); @@ -163,19 +154,20 @@ class UIMenu { var msg = "ArmorPaint.org - v" + App.version + " (" + date + ") - " + sha + "\n"; msg += kha.System.systemId + " - " + gapi; - if (kha.System.systemId == "Windows") { - var save = Krom.getFilesLocation() + "\\" + iron.data.Data.dataPath + "gpu.txt"; - Krom.sysCommand('wmic path win32_VideoController get name' + ' > "' + save + '"'); - var bytes = haxe.io.Bytes.ofData(Krom.loadBlob(save)); - var gpu = ""; - for (i in 30...Std.int(bytes.length / 2)) { - var c = String.fromCharCode(bytes.get(i * 2)); - if (c == '\n') continue; - gpu += c; - } - msg += '\n$gpu'; + #if krom_windows + var save = Krom.getFilesLocation() + "\\" + iron.data.Data.dataPath + "gpu.txt"; + Krom.sysCommand('wmic path win32_VideoController get name' + ' > "' + save + '"'); + var bytes = haxe.io.Bytes.ofData(Krom.loadBlob(save)); + var gpu = ""; + for (i in 30...Std.int(bytes.length / 2)) { + var c = String.fromCharCode(bytes.get(i * 2)); + if (c == '\n') continue; + gpu += c; } - // else { lshw -C display } + msg += '\n$gpu'; + #else + // { lshw -C display } + #end UIBox.showMessage(msg); } diff --git a/Sources/arm/ui/UITrait.hx b/Sources/arm/ui/UITrait.hx index e7cc16f3..fc929851 100644 --- a/Sources/arm/ui/UITrait.hx +++ b/Sources/arm/ui/UITrait.hx @@ -88,7 +88,6 @@ class UITrait extends iron.Trait { public var tabh = 0; public var ui:Zui; - public var systemId = ""; public var colorIdHandle = Id.handle(); public var formatType = 0; @@ -272,7 +271,6 @@ class UITrait extends iron.Trait { super(); inst = this; - systemId = kha.System.systemId; windowW = Std.int(defaultWindowW * App.C.window_scale); toolbarw = Std.int(defaultToolbarW * App.C.window_scale); @@ -780,12 +778,14 @@ class UITrait extends iron.Trait { hwnd.redraws = 2; } + #if krom_darwin + var undoPressed = !kb.down("shift") && kb.started("z"); // cmd+z on macos + var redoPressed = (kb.down("shift") && kb.started("z")) || kb.started("y"); // cmd+y on macos + #else var undoPressed = kb.down("control") && !kb.down("shift") && kb.started("z"); - if (systemId == 'OSX') undoPressed = !kb.down("shift") && kb.started("z"); // cmd+z on macos - var redoPressed = (kb.down("control") && kb.down("shift") && kb.started("z")) || kb.down("control") && kb.started("y"); - if (systemId == 'OSX') redoPressed = (kb.down("shift") && kb.started("z")) || kb.started("y"); // cmd+y on macos + #end if (undoPressed) History.doUndo(); else if (redoPressed) History.doRedo(); diff --git a/Sources/arm/util/Path.hx b/Sources/arm/util/Path.hx index 2c3e8165..3622588c 100644 --- a/Sources/arm/util/Path.hx +++ b/Sources/arm/util/Path.hx @@ -21,10 +21,10 @@ class Path { public static function baseDir(path:String):String { path = haxe.io.Path.normalize(path); var base = path.substr(0, path.lastIndexOf("/") + 1); - if (kha.System.systemId == "Windows") { - // base = StringTools.replace(base, "/", "\\"); - base = base.substr(0, 2) + "\\" + base.substr(3); - } + #if krom_windows + // base = StringTools.replace(base, "/", "\\"); + base = base.substr(0, 2) + "\\" + base.substr(3); + #end return base; } } diff --git a/khafile.js b/khafile.js index f365fb19..7b292b95 100644 --- a/khafile.js +++ b/khafile.js @@ -68,12 +68,15 @@ else { } if (process.platform === 'win32') { + project.addDefine('krom_windows'); project.addAssets("Bundled/cmft/cmft.exe", { notinlist: true , destination: "data/{name}" }); } else if (process.platform === 'linux') { + project.addDefine('krom_linux'); project.addAssets("Bundled/cmft/cmft-linux64", { notinlist: true , destination: "data/{name}" }); } else if (process.platform === 'darwin') { + project.addDefine('krom_darwin'); project.addAssets("Bundled/cmft/cmft-osx", { notinlist: true , destination: "data/{name}" }); }