E
E
Eugene2019-09-02 09:34:56
Lua
Eugene, 2019-09-02 09:34:56

How to add an outline (stroke) for text in LUA?

There is a GUI written in Lua and the LOVE framework . Depending on the situation, sometimes the fonts blend into the background (the color is all white), so I wanted to add a black stroke to all the texts. But as it turned out, LUA and the LOVE framework do not provide such an opportunity. However, on the net you can find implementation examples when the text is first drawn 8 times in black with offsets in different directions, and then white text is drawn on top. The problem is that I am not at all familiar with this language, and I have no idea how to implement it all correctly.
To initialize all text in general, a separate file is used, in which the following code:

function CFont:Init(name, size)
  self.size = size
  self.name = name
  self.font = lg.newFont( gPaths.fonts .. "/" .. self.name, self.size )
  self.font:setLineHeight( gFontLineHeight )
end

Or implement a stroke for one font, using this code as an example:
function CUIFg:InitBottomText(  )
  self.bottomText = ""
  self.bottomTextSize = 0
  self.bottomTextObjPosY = 0
  
  local font = Common:GetFont(10, gUIFonts.default)
  self.bottomTextObj = lg.newText(font)
  self.bottomTextObjScale 	= 0
  self.bottomTextObjHeight = self.bottomTextObj:getHeight()
  
  self.bottomTextBoxWidth, self.bottomTextBoxHeight = 620, 60
  self.bottomTextBoxX0, self.bottomTextBoxY0 = gViewport.width/2 - self.bottomTextBoxWidth/2, self.uiBottomPosY - self.bottomTextBoxHeight/2 - 35
  self.bottomTextBoxCenterX, self.bottomTextBoxCenterY = self.bottomTextBoxX0 + self.bottomTextBoxWidth/2, self.uiBottomPosY + 80 - self.bottomTextBoxHeight/2
end

Is it possible to add a couple of lines of code to these files to implement the idea? Yes, I know that this is a crutch, but everything is done for personal use, so all means are good.
In general, you need to make a stroke for all texts = 3px.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question