Thread Tools Display Modes
12-22-14, 08:38 AM   #1
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Simple Font Object Question

Hi all,

I seem to have forgot how to copy a font object because I want to use GameFontNormal except having it class coloured. The Global MUI_COLOR definitely works and shows the class colours and "missionbtn" is the name of the button I have created.

Do this works correctly to show the yellow/gold coloured text:
Lua Code:
  1. missionbtn:SetNormalFontObject("GameFontNormal");

But this code below is what I am using and does not copy / work correctly:

Lua Code:
  1. local font = CreateFont("MUI_ButtonFont");
  2. font:CopyFontObject("GameFontNormal");
  3. font:SetTextColor(MUI_COLOR.r, MUI_COLOR.g, MUI_COLOR.b, 1);
  4. missionbtn:SetNormalFontObject(font);
  5. missionbtn:SetHighlightFontObject(font);

It shows up as nothing, making the button text invisible.

Completely stuck because I thought this should work. Any help? ^^
Been on a long break from programming so probably just being really stupid!
  Reply With Quote
12-22-14, 12:15 PM   #2
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,290
Change CopyFontObject to SetFontObject.

But you don't have to use a template for this, since you can just read their default values and create the same font with :SetFont, :SetShadowColor and :SetShadowOffset.

http://wowprogramming.com/docs/widgets/FontInstance

GameFontNormal:
https://github.com/Resike/BlizzardIn...tStyles.xml#L3

SystemFont_Shadow_Med1_Outline:
https://github.com/Resike/BlizzardIn...dFonts.xml#L46

Last edited by Resike : 12-22-14 at 12:37 PM.
  Reply With Quote
12-22-14, 01:32 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Like this?

Lua Code:
  1. local text = frame:CreateFontString("MyText", nil, "GameFontNormal")
  2. local _, class = UnitClass("player")
  3. local classColor = RAID_CLASS_COLORS[class]
  4. text:SetTextColor(classColor.r, classColor.g, classColor.b, 1)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
12-22-14, 01:51 PM   #4
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Thank you, but it is a button so I need to access the button's text but I only know how to get the FontObject and of course that just makes all instances of that object the same text colour which is not ideal.

I don't want to mess with the shadow of the font etc.. just the text colour.

I still like how GameFontHighlight changes the text to white so I want to use that but when i set the text colour to class colour then usually it removes the turning to white effect. I was hoping to be lazy and use the font object's shadow style . I just wanted the normal font type class coloured on the button. Would that mean I need to create a new FontString on the button to do this? I thought I could just use the basic button text it inherits by default.

EDIT:
I tried using your method Seerah but that made the GameFontHighlight style inactive so it does not change to white when the mouse is over the button.

Lua Code:
  1. local missionbtn = CreateFrame("Button", "testbtn", Minimap);
  2. missionbtn:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 6, -2);
  3. missionbtn:SetSize(14, 14);
  4. missionbtn:SetHighlightFontObject("GameFontHighlight")
  5.  
  6. local text = missionbtn:CreateFontString("MyText", nil, "GameFontNormal")
  7. text:SetTextColor(MUI_COLOR.r, MUI_COLOR.g, MUI_COLOR.b, 1)
  8. missionbtn:SetFontString(text);

Last edited by Mayron : 12-22-14 at 02:03 PM.
  Reply With Quote
12-22-14, 02:14 PM   #5
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Lua Code:
  1. MUI_COLOR = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[select(2, UnitClass("player"))];
  2.  
  3. local missionbtn = CreateFrame("Button", "testbtn", Minimap);
  4. missionbtn:SetPoint("TOPLEFT", Minimap, "TOPLEFT", 6, -2);
  5. missionbtn:SetSize(14, 14);
  6. missionbtn:SetHighlightFontObject("GameFontHighlight")
  7.  
  8. local font = CreateFont("MUI_ButtonFont");
  9. font:CopyFontObject(GameFontNormal);
  10. font:SetTextColor(MUI_COLOR.r, MUI_COLOR.g, MUI_COLOR.b, 1);
  11. missionbtn:SetNormalFontObject(font);

This works perfectly fine but it does not show the text initially until you enter the button and then leave it. It shows the Normal Font Object only when you enter and leave and not onload which I do not understand why.

Last edited by Mayron : 12-22-14 at 02:18 PM.
  Reply With Quote
12-22-14, 02:30 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
What happens if you use Font:SetFontObject() instead?
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 12-22-14 at 02:55 PM.
  Reply With Quote
12-22-14, 02:35 PM   #7
Mayron
A Frostmaul Preserver
 
Mayron's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 275
Originally Posted by SDPhantom View Post
What happens if you use Font:SetFontObject() instead?
Ah that works thank you and sorry for not trying that the first time Resike mentioned it.
Brilliant! <3
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Simple Font Object Question

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off