Jump to content




[-FIXED-] [OpenPeripheral - Addons] Terminal Glasses - Center a text

help peripheral lua

2 replies to this topic

#1 RootSlayers

  • Members
  • 13 posts
  • LocationIn front of my Computer @LocalHost - France

Posted 27 July 2015 - 01:45 PM

Minecraft version : 1.7.10
Forge version : 10.13.4.1448
Computercraft version : 1.74
OpenPeripheralAddons version : 0.3.1

Hello world !

I work on HUD with OpenP. Addons and Terminal Glasses, it's quite similar to the Plastic Program made by 1lann, but I wanted to do it myself but I would summon your help because I'm stuck when i'm trying to center a text, the function worked perfectly with the previous version of Computercraft and OpenMods, but nowadays the sync() function disturbs me.


I know how to center a text :
math.ceil((BoxLengh/2) - (TextLengh/2))

The main box is 110px wide.
There is 10px between the border of the screen and the beginning of the main box.

Here an image to explain my problem :

http://gyazo.com/cd0...64d059ef516c991

I have this function to center the text :
function centerText(text, object)
	object.setText("")
	object.setText(text)
	local MidText = text:len()/2
	local PosX = 65 - MidText
	print(MidText)
	object.setX(PosX)
	Glasses.sync()  
end

I know I have to multiply the 'MidText' by a number but I don't know which one.

I've also tried to use the same function as 1lann but it didn't works anymore with this version :

His code :
math.ceil(((136/2)-(plastic.getStringWidth(text)*(0.65)/2))+20-0.5)

Modified, to match with mine (works with OpenP.Addons 0.2.0 snapshot):
((110/2 -10)-(Glasses.getStringWidth(text))*(0.65)/2))+20-0.5

Edited by RootSlayers, 31 July 2015 - 09:53 PM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 31 July 2015 - 05:31 AM

According to this, the multiplier you're after should be 5 * textScale.

#3 RootSlayers

  • Members
  • 13 posts
  • LocationIn front of my Computer @LocalHost - France

Posted 31 July 2015 - 10:21 AM

Hello !

Thanks a lot :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users