Skip to content

Commit f0fb5b5

Browse files
committed
HideHL/Texture: add fit zoom cmd
1 parent 5a3ae91 commit f0fb5b5

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

hide_hl/hide/view/Texture.hx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class Texture extends HuiView<{path: String}> {
8080

8181
static var _ = HuiView.register("texture", Texture);
8282

83+
static public var fitCmd = new hrt.ui.HuiCommands.HuiCommand("Fit", {key: hxd.Key.F});
84+
8385
static var TRANSPARENT_TEX_PATH = 'ui/transparent_tiles_dark.png';
8486
static var MIN_ZOOM = 0.01;
8587
static var DEFAULT_FILTER = "POINT";
@@ -100,11 +102,10 @@ class Texture extends HuiView<{path: String}> {
100102
initComponent();
101103

102104
registerCommand(HuiCommands.save, View, () -> { save();});
105+
registerCommand(fitCmd, View, () -> { fit();});
103106

104-
var fs : hxd.fs.LocalFileSystem = Std.downcast(hxd.res.Loader.currentInstance.fs, hxd.fs.LocalFileSystem);
105107
var dirPos = state.path.lastIndexOf("/");
106108
var dirPath = dirPos < 0 ? state.path : state.path.substr(0, dirPos + 1);
107-
var name = dirPos < 0 ? state.path : state.path.substr(dirPos + 1);
108109
propsFilePath = dirPath + "props.json";
109110

110111
// Create params from current texture conversion rule
@@ -213,6 +214,9 @@ class Texture extends HuiView<{path: String}> {
213214
}
214215

215216
refreshInspector();
217+
218+
// Center the texture after the first flow refresh
219+
haxe.Timer.delay(fit, 0);
216220
}
217221

218222
override function getViewName():String {
@@ -518,6 +522,14 @@ class Texture extends HuiView<{path: String}> {
518522
shader.uncompressedTex = uncompressedTex;
519523
}
520524

525+
function fit() {
526+
this.zoom = viewer.calculatedHeight / this.bmp.tile.height;
527+
refresh();
528+
this.pan.x = (viewer.calculatedWidth / 2) - (this.bmp.getSize().width / 2);
529+
this.pan.y = (viewer.calculatedHeight / 2) - (this.bmp.getSize().height / 2);
530+
refresh();
531+
}
532+
521533
function setChannelVisible(channelIdx : Int, visible : Bool) {
522534
shader.channels &= ~(1 << channelIdx);
523535
if (visible) shader.channels |= 1 << channelIdx;

0 commit comments

Comments
 (0)