WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Drawing a texture on top of fontstring (https://www.wowinterface.com/forums/showthread.php?t=55521)

Layback_ 06-26-17 06:55 AM

Drawing a texture on top of fontstring
 
Hi all,

Both texture and fontstring are drawn on same frame (frame.Health), but each are created via two separate functions, ComposeNameText() and ComposeReadyCheckIndicator() where ReadyCheckIndicator is created after NameText.

Lua Code:
  1. function ComposeNameText()
  2.     local nameText = frame.Health:CreateFontString(frame:GetName() .. "NameText", "OVERLAY");
  3. end

Lua Code:
  1. function ComposeReadyCheckIndicator()
  2.     local readyCheckIndicator = frame.Health:CreateTexture(frame:GetName() .. "ReadyCheckIndicator", "OVERLAY");
  3. end

Here's what it looks like at the moment.



I tried to use 'sublevel' argument, but unlike texture, fontstring doesn't seem to have a sublevel argument :(

At this stage, I've changed fontstring's draw layer to "ARTWORK" as a temporary solution.

My question is would modifying draw layer be the only solution to solve this problem?

Aftermathhqt 06-26-17 07:25 AM

Quote:

Originally Posted by Layback_ (Post 323984)
Hi all,

Both texture and fontstring are drawn on same frame (frame.Health), but each are created via two separate functions, ComposeNameText() and ComposeReadyCheckIndicator() where ReadyCheckIndicator is created after NameText.

Lua Code:
  1. function ComposeNameText()
  2.     local nameText = frame.Health:CreateFontString(frame:GetName() .. "NameText", "OVERLAY");
  3. end

Lua Code:
  1. function ComposeReadyCheckIndicator()
  2.     local readyCheckIndicator = frame.Health:CreateTexture(frame:GetName() .. "ReadyCheckIndicator", "OVERLAY");
  3. end

Here's what it looks like at the moment.



I tried to use 'sublevel' argument, but unlike texture, fontstring doesn't seem to have a sublevel argument :(

At this stage, I've changed fontstring's draw layer to "ARTWORK" as a temporary solution.

My question is would modifying draw layer be the only solution to solve this problem?

Just create a invisible frame, then attach the text or icon which ever you want to be highest frame level.

Gethe 06-26-17 10:05 AM

Quote:

Originally Posted by Layback_ (Post 323984)
At this stage, I've changed fontstring's draw layer to "ARTWORK" as a temporary solution.

My question is would modifying draw layer be the only solution to solve this problem?

You can use SetDrawLayer, which has an optional parameter for subLevel. It works with both fonts and textures.

MunkDev 06-26-17 10:09 AM

Regions should have a sublevel argument; the fourth parameter on creation:
Lua Code:
  1. texture = frame:CreateTexture(["name" [, "layer" [, "inherits" [, sublevel]]]])

All regions also have the :SetDrawLayer method.
Lua Code:
  1. region:SetDrawLayer("layer", sublayer)

Layback_ 06-26-17 06:04 PM

Hi

@Game92, thank you for your idea, but I don't want to waste a resource only to draw one region on top of another ;)

@Gethe & MunkDev, After I've posted this, I tried SetDrawLayer, but no luck :(

It still has a same result as it's shown below.



Lua Code:
  1. local text = UIParent:CreateFontString();
  2. text:SetDrawLayer("ARTWORK", -8);
  3. text:SetFont(LSM:Fetch("font", "koverwatch"), 24, "OUTLINE");
  4. text:SetPoint("CENTER");
  5. text:SetText("Text");
  6.  
  7. local texture = UIParent:CreateTexture();
  8. texture:SetDrawLayer("ARTWORK", 7);
  9. texture:SetTexture(READY_CHECK_READY_TEXTURE);
  10. texture:SetPoint("CENTER");
  11. texture:SetSize(36, 36);

AFAIK, sublevel argument should change the rendering order of regions in same layer where 7 is the highest order while -8 is the lowest order, but the texture is still drawn at the back :confused:

I also tested with different layers, but still didn't work out..

*EDIT: Creating fontstring after texture did not solve this problem as well.

Fizzlemizz 06-26-17 06:39 PM

Have you tried setting the BlendMode?

lightspark 06-26-17 09:28 PM

The "problem" is that FontStrings ALWAYS use the highest sublevel of the layer, it doesn't matter what your set.

So to address your issue, I'd either put your text on a lower layer: ARTWORK, or move your texture to a higher layer: HIGHLIGHT.

Lua Code:
  1. local text = UIParent:CreateFontString()
  2. text:SetDrawLayer("ARTWORK")
  3. text:SetFont(LSM:Fetch("font", "koverwatch"), 24, "OUTLINE")
  4. text:SetPoint("CENTER")
  5. text:SetText("Text")
  6.  
  7. local texture = UIParent:CreateTexture()
  8. texture:SetDrawLayer("OVERLAY")
  9. texture:SetTexture(READY_CHECK_READY_TEXTURE)
  10. texture:SetPoint("CENTER")
  11. texture:SetSize(36, 36)

Creating additional frames and using them as parents for your FontStrings and Textures is a solution too, it's viable if you have really complex unit frames w/ multiple layers of textures and/or texts, otherwise it's an overkill.

Layback_ 06-27-17 12:15 AM

Hi

@Fizzlemizz, No, I haven't tried that one, but would that do a trick in this case?

@lightspark, Ah..... that's why....... I didn't know that fontstring takes the highest place of sublevel :(

In my case, I should put texture on "OVERLAY" and text on "ARTWORK", right?
(Since I am expecting texture to be on top of text)

lightspark 06-27-17 02:05 AM

Quote:

Originally Posted by Layback_ (Post 324010)
@lightspark, Ah..... that's why....... I didn't know that fontstring takes the highest place of sublevel :(

In my case, I should put texture on "OVERLAY" and text on "ARTWORK", right?
(Since I am expecting texture to be on top of text)

Please, take a look at the code block I posted. I used your code, but fixed layers.

Also, you can assign layers and sublevels by passing them to CreateTexture and CreateFontString. I dunno why you're using SetDrawLayer.

Layback_ 06-27-17 04:29 AM

Quote:

Originally Posted by lightspark (Post 324011)
Please, take a look at the code block I posted. I used your code, but fixed layers.

My bad haha...

I only read your comment, not code :p

Quote:

Originally Posted by lightspark (Post 324006)
I'd either put your texture on a lower layer: ARTWORK, or move your text to an higher layer: HIGHLIGHT


Quote:

Originally Posted by lightspark (Post 324011)
Also, you can assign layers and sublevels by passing them to CreateTexture and CreateFontString. I dunno why you're using SetDrawLayer.

When I checked an API on wowprogramming and wowpedia, CreateFontString didn't seem to have a sublevel argument :confused:

So I chose to use SetDrawLayer instead of setting layer and sublevel argument on Creation.

But, since I know that fontstrings are always set to have highest sublevel, I don't need to use SetDrawLayer like you said :)

Thanks for clarification.

lightspark 06-27-17 05:42 AM

Quote:

Originally Posted by Layback_ (Post 324013)
My bad haha...

I only read your comment, not code :p

K, I fixed higher/lower typo :p

Layback_ 06-27-17 08:51 AM

Quote:

Originally Posted by lightspark (Post 324014)
K, I fixed higher/lower typo :p

:banana:! :banana:! :banana:! :banana:!

SDPhantom 06-27-17 04:43 PM

Quote:

Originally Posted by lightspark (Post 324006)
I'd either put your text on a lower layer: ARTWORK, or move your texture to a higher layer: HIGHLIGHT.

HIGHLIGHT is a special layer that only shows on mouseover. Don't use it unless you need this behavior.


All times are GMT -6. The time now is 02:24 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI