diff --git a/kramv/KramViewerBase.cpp b/kramv/KramViewerBase.cpp index 101abf70..da4482ff 100644 --- a/kramv/KramViewerBase.cpp +++ b/kramv/KramViewerBase.cpp @@ -961,11 +961,14 @@ bool isPtInRect(float2 pt, float4 r) return all((pt >= r.xy) & (pt <= r.xy + r.zw)); } -const Atlas* Data::findAtlasAtCursor(float2 pt) +const Atlas* Data::findAtlasAtUV(float2 pt) { + if (_showSettings->atlas.empty()) return nullptr; + if (_showSettings->imageBoundsX == 0) return nullptr; + const Atlas* atlas = nullptr; - // TODO: rects are in uv, so need to convert pt + // Note: rects are in uv // This might need to become an atlas array index instead of ptr const Atlas* lastAtlas = _showSettings->lastAtlas; @@ -1447,6 +1450,8 @@ void Data::showEyedropperData(const float2& uv) break; } + // TODO: indicate px, mip, etc (f.e. showAll) + // debug mode // preview vs. not @@ -1480,10 +1485,6 @@ void Data::showEyedropperData(const float2& uv) mipX = (int32_t)(uv.x * mipX); mipY = (int32_t)(uv.y * mipY); - // Has to be set in other call, not here - //_showSettings->textureLookupMipX = mipX; - //_showSettings->textureLookupMipY = mipY; - // TODO: may want to return mip in pixel readback // don't have it right now, so don't display if preview is enabled if (_showSettings->isPreview) @@ -1605,7 +1606,12 @@ void Data::setEyedropperText(const char * text) setTextSlot(kTextSlotEyedropper, text); } -string Data::textFromSlots() const +void Data::setAtlasText(const char * text) +{ + setTextSlot(kTextSlotAtlas, text); +} + +string Data::textFromSlots(bool isFileListHidden) const { // combine textSlots string text = _textSlots[kTextSlotHud]; @@ -1613,9 +1619,15 @@ string Data::textFromSlots() const text += "\n"; // don't show eyedropper text with table up, it's many lines and overlaps - // TODO: fix - // if (!_tableView.hidden) + if (!isFileListHidden) + { text += _textSlots[kTextSlotEyedropper]; + if (!text.empty() && text.back() != '\n') + text += "\n"; + + text += _textSlots[kTextSlotAtlas]; + } + return text; } diff --git a/kramv/KramViewerBase.h b/kramv/KramViewerBase.h index 70b2b852..fe08150c 100644 --- a/kramv/KramViewerBase.h +++ b/kramv/KramViewerBase.h @@ -412,7 +412,8 @@ struct ActionState enum TextSlot { kTextSlotHud, - kTextSlotEyedropper + kTextSlotEyedropper, + kTextSlotAtlas }; struct File { @@ -464,7 +465,7 @@ struct Data { bool findFilename(const string& filename); bool findFilenameShort(const string& filename); - const Atlas* findAtlasAtCursor(float2 pt); + const Atlas* findAtlasAtUV(float2 uv); bool isArchive() const; bool loadFile(); @@ -482,7 +483,7 @@ struct Data { vector& actions() { return _actions; } void initDisabledButtons(); - string textFromSlots() const; + string textFromSlots(bool isFileListHidden) const; void setTextSlot(TextSlot slot, const char* text); void loadFilesFromUrls(vector& urls, bool skipSubdirs); @@ -507,8 +508,9 @@ struct Data { public: void showEyedropperData(const float2& uv); void setEyedropperText(const char * text); + void setAtlasText(const char * text); void updateTransforms(); - + //---------------- float4x4 _projectionMatrix; diff --git a/kramv/KramViewerMain.mm b/kramv/KramViewerMain.mm index 0070590b..5e636daa 100644 --- a/kramv/KramViewerMain.mm +++ b/kramv/KramViewerMain.mm @@ -1082,12 +1082,32 @@ -(void)updateEyedropperText if (_showSettings->imageBoundsX == 0) return; float2 uv; - uv.x = _showSettings->textureLookupX / _showSettings->imageBoundsX; - uv.y = _showSettings->textureLookupY / _showSettings->imageBoundsY; + uv.x = _showSettings->textureLookupX / (float)_showSettings->imageBoundsX; + uv.y = _showSettings->textureLookupY / (float)_showSettings->imageBoundsY; // convert data to text _data.showEyedropperData(uv); + const Atlas* atlas = _data.findAtlasAtUV(uv); + if (atlas) { + // convert back to pixels in the current mip + float mipBoundsX = std::max(1, _showSettings->imageBoundsX >> _showSettings->mipNumber); + float mipBoundsY = std::max(1, _showSettings->imageBoundsY >> _showSettings->mipNumber); + + float4 rect = atlas->rect(); + rect.xz *= mipBoundsX; + rect.yw *= mipBoundsY; + + string atlasText; + sprintf(atlasText, "%d,%d %dx%d %s", + (int32_t)rect.x, (int32_t)rect.y, + (int32_t)rect.z, (int32_t)rect.w, + atlas->name.c_str()); + _data.setAtlasText(atlasText.c_str()); + } + else { + _data.setAtlasText(""); + } // This calls setNeedsDisplay on the hud section that displays the eyeDropper [self updateHudText]; } @@ -1107,7 +1127,7 @@ - (void)setHudText:(const char *)text - (void)updateHudText { // combine textSlots - string text = _data.textFromSlots(); + string text = _data.textFromSlots(_tableView.hidden); NSString *textNS = [NSString stringWithUTF8String:text.c_str()];