.TTF Texter!

  • FeynmanLogomaker
    15th Oct 2013 Member 0 Permalink

    WARNING: This can count as CGI, if you use this for certain uses you may be banned! 


     


    This may be one of the most powerful texters yet made on TPT; see this:



    for an example.


     


    The files are all here: https://www.dropbox.com/s/el82lsgj1fwg1j1/_GD%20Texter.zip


     


    To set it up, copy all of the files in the .zip to the same folter that Powder Toy is in, and if you use cracker64's script manager, copy the Lua file into the scripts folder. If you use the script manager, don't put the DLLs in your scripts folder; they won't be found there.


     


    To use it, you just press CTRL-T, and it will open up an interface where you can enter the size, color, font and text. Once you close the interface, it draws the text you gave at the mouse coordinates.


     


    One downside though - it can only take the font filename, which you can find in the folder where all of your fonts are stored. For example, if you wanted to use Consolas, you would actually have to enter the name 'Consola' ('Consolas.ttf').


     



     



     



     


    Ver. 1:     Wrote a script.


    Ver. 1.8:  Added cool text placement thingy! Now you have a lot more control of the placement of the text.


    Ver. 2.0:  Added color to the placement box, increased precision a little.


    Ver. 2.5: Included all the other DLLs you might need to run it, changed default font to Segoe UI Light.


    Ver. 2.8: Added rotation! (Now takes it in degrees)


     


    The current code:


     


    require 'gd'

    function gdText(text, size, font, r, g, b, rotation)
    local r, g, b = r, g, b
    if not r then r, g, b, rotation = 255, 255, 255, 0 end
    local im = gd.createTrueColor(610, 380)
    local llx, lly, lrx, lry, urx, ury, ulx, uly, pos = im:stringFT(im:colorAllocate(tonumber(r), tonumber(g), tonumber(b), 255), font, size, math.rad(360 - rotation), 0, size, text)
    function drawFontRect()
    tpt.drawrect(tpt.mousex, tpt.mousey, lrx - ulx, lry - uly, r, g, b, 255)
    for cx = ulx, lrx do
    for cy = uly, lry do
    local col = im:getPixel(cx, cy)
    if col > 0 then
    col = bit.tohex(col)
    if tpt.mousex + cx < 610 and tpt.mousey + cy < 380 then
    graphics.fillRect(tpt.mousex + cx, tpt.mousey + cy, 1, 1, tonumber(string.sub(col, 3, 4)), tonumber(string.sub(col, 5, 6)), tonumber(string.sub(col, 7, 8)), 255)
    end
    end
    end
    end
    end
    tpt.register_step(drawFontRect)
    function stopFontRect(x, y, b, e)
    if e == 2 then
    for cx = ulx, lrx do
    for cy = uly, lry do
    local col = im:getPixel(cx, cy)
    if col > 0 then
    col = bit.tohex(col)
    if x + cx < 610 and y + cy < 380 then
    tpt.create(x + cx, y + cy, 'dmnd')
    tpt.set_property('dcolor', '0xFF' .. string.sub(col, 3, 4) .. string.sub(col, 5, 6) .. string.sub(col, 7, 8), x + cx, y + cy)
    end
    end
    end
    end
    tpt.unregister_step(drawFontRect)
    tpt.unregister_mouseclick(stopFontRect)
    end
    return false
    end
    tpt.register_mouseclick(stopFontRect)
    end

    local imOut = gd.create ( 610, 380 )
    local cols, collist = {}, {}
    for i, v in pairs ( tpt.el ) do

    if i ~= 'grav' and i ~= 'fire' and i ~= 'exot' and i ~= 'gpmp' and i ~= 'pump' and i ~= 'stor'
    and i ~= 'cflm' and i ~= 'plsm' and i ~= 'glow' and i ~= 'lava' and i ~= 'qrtz' and i ~= 'figh'
    and i ~= 'tron' and i ~= 'stkm' and i ~= 'bran' and i ~= 'embr' and i ~= 'clst' and i ~= 'stk2'
    and ( elements [ 'DEFAULT_PT_' .. string.upper ( i ) ] or i == 'virs' ) and i ~= 'pqrt'
    and i ~= 'spwn' and i ~= 'spwn2' and i ~= 'bubw' and i ~= 'filt' and i ~= 'deut' and i ~= 'bizr'
    and i ~= 'bizg' and i ~= 'bizs' and i ~= 'wifi' then

    if i == 'warp' then

    cr, cg, cb = 0 , 0 , 0

    elseif i == 'virs' then

    cr, cg, cb = 254 , 17 , 246
    debug.virsused = true

    else

    color = bit.tohex ( tpt.el [ i ] [ 'color' ] , 8 )
    cr = tonumber ( string.sub(color, 3, 4) , 16 )
    cg = tonumber ( string.sub(color, 5, 6) , 16 )
    cb = tonumber ( string.sub(color, 7, 8) , 16 )

    end

    if i == 'virs' then

    cols [ 'virs' ] = imOut:colorAllocate ( 254, 27, 246 )
    --print ( color )
    collist [ cols [ 'virs' ] ] = 'virs'

    else

    cols [ i ] = imOut:colorAllocate ( cr , cg , cb )
    --print ( color )
    if not ( cols [ i ] == nil or cols [ i ] == 0 or cols [ i ] == '' ) then
    collist [ cols [ i ] ] = i
    else
    debug.bugelems [ dk ] = i
    dk = dk + 1
    print ( i )
    end

    end

    end

    end

    function gdTextElems(text, size, font, r, g, b, rotation)
    --local cols, collist = {} , {}

    --[[
    debug.bugelems = {}
    local dk = 1
    --]]
    local r, g, b = r, g, b
    if not r then r, g, b, rotation = 255, 255, 255, 0 end
    local im = gd.createTrueColor(610, 380)

    local llx, lly, lrx, lry, urx, ury, ulx, uly, pos = im:stringFT(im:colorAllocate(tonumber(r), tonumber(g), tonumber(b), 255), font, size, math.rad(360 - rotation), 0, size, text)
    function drawFontRect()
    tpt.drawrect(tpt.mousex, tpt.mousey, lrx - ulx, lry - uly, r, g, b, 255)
    for cx = ulx, lrx do
    for cy = uly, lry do
    local col = im:getPixel(cx, cy)
    if col > 0 then
    col = bit.tohex(col)
    if tpt.mousex + cx < 610 and tpt.mousey + cy < 380 then
    graphics.fillRect(tpt.mousex + cx, tpt.mousey + cy, 1, 1, tonumber(string.sub(col, 3, 4)), tonumber(string.sub(col, 5, 6)), tonumber(string.sub(col, 7, 8)), 255)
    end
    end
    end
    end
    end
    tpt.register_step(drawFontRect)
    function stopFontRect(x, y, b, e)
    if e == 2 then
    for cx = ulx, lrx do
    for cy = uly, lry do
    local col = im:getPixel(cx, cy)
    if col > 0 then

    local ccol = col
    --and take the r, g, b individual values.
    cr, cg, cb = im:red ( ccol ) , im:green ( ccol ) , im:blue ( ccol )
    rcol = imOut:colorClosest ( cr , cg , cb )
    --print ( collist [ rcol ] )

    --tpt.create ( x , y , collist [ bit.tohex ( r , 2 ) .. bit.tohex ( g , 2 ) .. bit.tohex ( b , 2 ) ] )

    if collist [ rcol ] ~= '' and collist [ rcol ] ~= 'warp' then
    if collist [ rcol ] == 'sprk' then
    tpt.create ( x + cx , y + cy , 'metl' )
    tpt.create ( x + cx , y + cy , 'sprk' )
    else
    tpt.create ( x + cx , y + cy , collist[rcol] )
    --[[
    if _debug == 0 then
    debug.bugelems [ dk ] = collist [ rcol ]
    dk = dk + 1
    print( collist [ rcol ] )
    end
    --]]
    end
    end

    --end
    end
    end
    end
    tpt.unregister_step(drawFontRect)
    tpt.unregister_mouseclick(stopFontRect)
    end
    return false
    end
    tpt.register_mouseclick(stopFontRect)
    end

    local texterstr, texterstr2, texterstr3, texterstr4, texterstr5, texterstr6, texterstr7, texterstr8 = 'Hello world!', '', 'SegoeUIL', '255', '255', '255', '16', '0'

    gdtexter_key_test = function(a, b, c, d)
    if (a == 't' and c == 64) or (a == 't' and c == 65) then
    local cmx, cmy = tpt.mousex, tpt.mousey
    local texterWindow = Window:new(-1, -1, 525, 300)

    local currentY = 10

    local tbs = 55

    local plotStr1 = Textbox:new(tbs + 10, currentY, (select(1, texterWindow:size()))-(tbs+20), 16, texterstr, "[place text here]")
    plotStr1:onTextChanged(
    function(sender)
    texterstr = plotStr1:text()
    end
    )

    local plotStr1Lbl = Label:new(10, currentY, tbs, 16, "Text: ")

    currentY = currentY + 20

    local plotStr2 = Textbox:new(tbs + 10, currentY, (select(1, texterWindow:size()))-(tbs+20), 16, texterstr2, "[and here, if you need more space]")
    plotStr2:onTextChanged(
    function(sender)
    texterstr2 = plotStr2:text();
    end
    )

    local plotStr2Lbl = Label:new(10, currentY, tbs, 16, "Text: ")

    currentY = currentY + 20

    local fontName = Textbox:new(tbs + 10, currentY, (select(1, texterWindow:size()))-(tbs+20), 16, texterstr3, "Font used")
    fontName:onTextChanged(
    function(sender)
    texterstr3 = fontName:text();
    end
    )

    local fontNameLbl = Label:new(10, currentY, tbs, 16, "Font Name: ")

    currentY = currentY + 20

    local colorR = Slider:new((tbs+7), currentY, (select(1, texterWindow:size()))-(tbs+50), 16, 255)
    colorR:onValueChanged(
    function(sender)
    texterstr4 = colorR:value()-- / ((select(1, texterWindow:size()))-50) * 255;
    colorRLbl:text(math.floor(texterstr4))
    end
    )

    colorR:value(texterstr4 / 255 * ((select(1, texterWindow:size()))-50))

    colorRLbl = Label:new((select(1, texterWindow:size()))-50, currentY, 50, 16, math.floor(texterstr4))

    local sliderRLbl = Label:new(10, currentY, tbs, 16, "Red: ")

    currentY = currentY + 20

    local colorG = Slider:new((tbs+7), currentY, (select(1, texterWindow:size()))-(tbs+50), 16, 255)
    colorG:onValueChanged(
    function(sender)
    texterstr5 = colorG:value()-- / ((select(1, texterWindow:size()))-50) * 255;
    colorGLbl:text(math.floor(texterstr5))
    end
    )

    colorG:value(texterstr5 / 255 * ((select(1, texterWindow:size()))-50))

    colorGLbl = Label:new((select(1, texterWindow:size()))-50, currentY, 50, 16, math.floor(texterstr5))

    local sliderGLbl = Label:new(10, currentY, tbs, 16, "Green: ")

    currentY = currentY + 20

    local colorB = Slider:new((tbs+7), currentY, (select(1, texterWindow:size()))-(tbs+50), 16, 255)
    colorB:onValueChanged(
    function(sender)
    texterstr6 = colorB:value()-- / ((select(1, texterWindow:size()))-50) * 255;
    colorBLbl:text(math.floor(texterstr6))
    end
    )

    colorB:value(texterstr6 / 255 * ((select(1, texterWindow:size()))-50))

    colorBLbl = Label:new((select(1, texterWindow:size()))-50, currentY, 50, 16, math.floor(texterstr6))

    local sliderBLbl = Label:new(10, currentY, tbs, 16, "Blue: ")

    currentY = currentY + 20

    local size = Textbox:new(tbs+10, currentY, (select(1, texterWindow:size()))-(tbs+20), 16, texterstr7, "Size")
    size:onTextChanged(
    function(sender)
    texterstr7 = size:text();
    end
    )

    local sizeLbl = Label:new(10, currentY, tbs, 16, "Font Size: ")

    currentY = currentY + 20

    local rotation = Textbox:new(tbs+10, currentY, (select(1, texterWindow:size()))-(tbs+20), 16, texterstr8, "Rotation")
    rotation:onTextChanged(
    function(sender)
    texterstr8 = rotation:text();
    end
    )

    local rotationLbl = Label:new(10, currentY, tbs, 16, "Rotation: ")

    local closeButton = Button:new(10, select(2, texterWindow:size())-26, 100, 16, "Draw text")

    closeButton:action(function()
    interface.closeWindow(texterWindow)
    if c == 64 then
    gdText(string.gsub(texterstr, '\\n', '\n') .. '\n' .. string.gsub(texterstr2, '\\n', '\n'), tonumber(texterstr7), texterstr3, tonumber(texterstr4), tonumber(texterstr5), tonumber(texterstr6), tonumber(texterstr8))
    else
    gdTextElems(string.gsub(texterstr, '\\n', '\n') .. '\n' .. string.gsub(texterstr2, '\\n', '\n'), tonumber(texterstr7), texterstr3, tonumber(texterstr4), tonumber(texterstr5), tonumber(texterstr6), tonumber(texterstr8))

    end
    end
    )

    texterWindow:onTryExit(function() interface.closeWindow(texterWindow) end) -- Allow the default exit events

    texterWindow:addComponent(plotStr1)
    texterWindow:addComponent(plotStr1Lbl)

    texterWindow:addComponent(plotStr2)
    texterWindow:addComponent(plotStr2Lbl)

    texterWindow:addComponent(fontName)
    texterWindow:addComponent(fontNameLbl)

    texterWindow:addComponent(colorR)
    texterWindow:addComponent(colorRLbl)
    texterWindow:addComponent(sliderRLbl)

    texterWindow:addComponent(colorG)
    texterWindow:addComponent(colorGLbl)
    texterWindow:addComponent(sliderGLbl)

    texterWindow:addComponent(colorB)
    texterWindow:addComponent(colorBLbl)
    texterWindow:addComponent(sliderBLbl)

    texterWindow:addComponent(size)
    texterWindow:addComponent(sizeLbl)

    texterWindow:addComponent(rotation)
    texterWindow:addComponent(rotationLbl)

    texterWindow:addComponent(closeButton)

    interface.showWindow(texterWindow)
    end
    end

    tpt.register_keypress(gdtexter_key_test)

    Edited 13 times by FeynmanLogomaker. Last: 8th Jun 2014
  • mniip
    15th Oct 2013 Developer 0 Permalink
    pffffffffffffffft, >gd
    well there's a bug, it doesn't quite work on linux
    Edited once by mniip. Last: 15th Oct 2013
  • FeynmanLogomaker
    15th Oct 2013 Member 0 Permalink

    Yeah, GD just is there to make it easier on me...

    But it can do pretty fonts :3

  • Iridium616
    15th Oct 2013 Member 0 Permalink

    Cannot open scripts: invalid argument; It says something about missing lua51.dl

    Edited once by Iridium616. Last: 15th Oct 2013
  • FeynmanLogomaker
    15th Oct 2013 Member 0 Permalink

    Oh, really? I'll fix that when I get home, although you may be able to find that in the dll pack.

  • Nobody905
    15th Oct 2013 Member 0 Permalink

    Nice... Now I can write pretty text in TPT (Segoe WP, yeaaahhh). 

    And the use of this is...

    Couldn't find any, if you make small text there's little to no difference between fonts and if you make it big it uses too much space on the screen.

    So, pretty useless. But as a Lua experiment it is, indeed, amazing.

  • FeynmanLogomaker
    15th Oct 2013 Member 0 Permalink

    There, I think I have all the necessary DLLs.

  • Nobody905
    15th Oct 2013 Member 0 Permalink

    Ban Comic Sans, that is the font of Satan.

    Make it just crash TPT if you try to use Comic Sans.

  • Lockheedmartin
    15th Oct 2013 Moderator 0 Permalink

    Note the fact people should be careful using this. Using this in certain ways (Taking credit for font creation, etc) could be counted as CGI. From what I remembered this was encountered in the past and had the same rules imposed on it.

     

    Also ban papyrus ._.

  • boxmein
    15th Oct 2013 Former Staff 0 Permalink
    @Lockheedmartin (View Post)
    Yeah anyone using Papyrus should in fact be banned due to not being a functioning member of society.